Skip to content

1.x: fix switchMap/switchOnNext producer retention and backpressure #3836

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 7, 2016

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Apr 6, 2016

This PR fixes the producer retention problem and backpressure problem in switchMap/switchOnNext.

In the original, when an inner source completed, its producer was still referenced after it. If there was no new inner source or the next inner source didn't set a new producer, the operator leaked the previous inner source's internals. The fix involves nulling out the producer field when the inner source completes (and is still the current one).

The original had an additional bug due to a race condition between the request arbitration and switching inner sources. In some cases, the switch didn't properly forward the remaining request amount to the new inner source, causing hangs. In some other cases, both the old and new inner sources were able to emit, causing overflow. The fix involves a new queue-drain loop with some emitter-loop help to work out the state transitions.

@akarnokd akarnokd added the Bug label Apr 6, 2016
@akarnokd akarnokd force-pushed the SwitchMapRewrite1x branch 2 times, most recently from 7bb7ffc to 3d7c0c9 Compare April 6, 2016 13:44
@stevegury
Copy link
Member

👍

@akarnokd akarnokd merged commit bcd7fa1 into ReactiveX:1.x Apr 7, 2016
@akarnokd akarnokd deleted the SwitchMapRewrite1x branch April 7, 2016 07:00
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