2.x: fix cross-boundary invalid fusion with observeOn, flatMap & zip #4984
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
flatMap
andzip
fuses its sources, it was possible one of the async source polls on another source which executed boundary-sensitive operators (map
,filter
) on the wrong thread.For clarity, here is a diagram showing the execution flow of a classical and fused setup:
In the classical flow, everything is push and when flatMap collects the available elements, all side-effects happened inside
map
.In the fused flow, there are no queues and the onNext call is an indication to
poll()
on the sources insideflatMap
(or zip). If the first source triggers onNext, that source is correctly polled andmap
executes on the right thread. However, when the flatMap continues to collect other available elements, it polls on the other source and executes thatmap
still on the first scheduler, despite that source having its own scheduler specified.The solution is to mark
flatMap
andzip
's inner consumer as boundary sensitive which prevents the fusion above sincemap
is also marked as boundary sensitive.Related: reactor/reactor-core#342