3.x: Fix Flowable.groupBy cancellation/cleanup/eviction race hangs #6979
+155
−36
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.
This PR fixes three additional race conditions from #6974 (comment)
When a cancellation arrived asynchronously to a group, the drain loop quit and left unconsumed items in the queue and thus prevented the replenishment from the main upstream. Fix: change the drain loop to always clean & replenish upon seeing a canceled state.
When a cancellation was detected just after the drain loop has polled from the queue, that polled item was ignored and not replenished. Fix: Include the non-empty polled item in the replenishment count upon cancellation.
When a cancellation happened concurrently with an eviction, both could end up decrementing the group counter into an invalid (negative) number, preventing the operator to function properly. Fix: make sure group removal accounting happens at most once.
Fixes: #6974