Skip to content

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

Merged
akarnokd merged 1 commit intoReactiveX:1.xfrom
akarnokd:SwitchMapRewrite1x
Apr 7, 2016
Merged

1.x: fix switchMap/switchOnNext producer retention and backpressure#3836
akarnokd merged 1 commit intoReactiveX:1.xfrom
akarnokd:SwitchMapRewrite1x

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