Skip to content

1.x: fix takeLast() backpressure #3839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2016

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Apr 7, 2016

The counted and timed versions of takeLast had a concurrency bug which allowed concurrent emission from the underlying queue that holds onto the values till the upstream completes. When timed correctly, both an onCompleted() and a request() that went from 0 to n could enter the emit() method and break the internal state of the non-concurrent queue. Note that this queue doesn't have to be concurrent by nature because the operator can emit only after the upstream completes (offer() never runs concurrently with poll() unlike in observeOn).

In addition, the emission didn't immediately complete if the queue was emptied and requested == 0. In this operator, the fact that the queue became empty is the indicator of completion.

Both issues can be fixed with the postCompleteXXX mechanics in BackpressureUtils.

Since the operator has to store null values, the postCompleteXXX had to be extended with an exit transform overload to allow converting the NotificationLite values back to regular T/null.

@akarnokd akarnokd force-pushed the TakeLastBackpressurFix branch from f49eabe to b594a04 Compare April 7, 2016 11:52
@stevegury
Copy link
Member

👍

@akarnokd akarnokd merged commit 0fa142f into ReactiveX:1.x Apr 8, 2016
@akarnokd akarnokd deleted the TakeLastBackpressurFix branch April 8, 2016 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants