Repository navigation
4.x: Fix SubscriptionArbiter installing a subscription after cancel() - #8405
Merged
Merged
Conversation
akarnokd
requested changes
Nov 25, 2026
akarnokd
left a comment
Member
There was a problem hiding this comment.
Please put the test into the SubscriptionArbiterIsolatedTest.java with the @Isolated marker, similar to other isolated tests using the race().
setSubscription checked `cancelled` only before taking the WIP slot. A cancel() whose whole drain ran in between cancelled the previous subscription only; the new one was then installed, requested from and never cancelled. Re-check `cancelled` after winning the slot. Resolves ReactiveX#8404 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vzhn
force-pushed
the
fix-arbiter-cancel-race
branch
from
November 25, 2026 15:38
f8c287b to
cf68c1e
Compare
Contributor
Author
|
done |
akarnokd
approved these changes
Nov 25, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.x #8405 +/- ##
============================================
- Coverage 98.62% 98.61% -0.02%
- Complexity 7180 7183 +3
============================================
Files 826 826
Lines 51038 51043 +5
Branches 6944 6946 +2
============================================
- Hits 50338 50337 -1
+ Misses 478 477 -1
- Partials 222 229 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #8404.
SubscriptionArbiter.setSubscriptioncheckedcancelledonly before taking the WIP slot. Acancel()whose whole drain ran in between cancelled the previous subscription only. The new one was then installed, requested from and never cancelled. This affects every operator built on the arbiter (concat, concatMap, onErrorResume*, retry, repeat, repeatUntil, repeatWhen, switchIfEmpty, timeout with fallback).The fix re-checks
cancelledright after winning the slot. If it is set, it cancels the new subscription, leaves the slot as usual (decrementAndGet, anddrainLoopif work was missed) and returns. Acancel()that starts after the CAS increments WIP, so the existingdrainLoopcall handles it.Test:
SubscriptionArbiterIsolatedTest.setSubscriptionRaceWithCancel(@Isolated, moved there in review) racessetSubscriptionagainstcancel()forRACE_LONG_LOOPSrounds and asserts that the new subscription ends up cancelled. Without the fix it failed locally (at round 524, and at round 5765 in the isolated class); with the fix it passes.How I ran it: this machine has no JDK 26, so I did not run the Gradle build. I compiled the test sources with JDK 25 and ran them with the JUnit 6.0 launcher:
SubscriptionArbiterIsolatedTest: 1 passed;SubscriptionArbiterTest: 16 passed (each also skipsRxJavaTest.announce, which is@Disabled).validatorspackage: 272 passed, 27 skipped, 0 failed.AI disclosure: the race was found with a model checker for Java concurrency (vika) on 3.x. The fix, the test and this text were written with Claude (Claude Code), which also ran the checks described above. The same change fixes 3.x's
SubscriptionArbiter, which is identical apart from the package and theorg.reactivestreamstypes, if a backport is wanted.🤖 Generated with Claude Code