Skip to content

3.x: Workaround for FutureTask.toString + JDK 11 build #7173

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
Feb 1, 2021

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Jan 30, 2021

Starting from JDK 10, the FutureTask.toString can now print the inner callable routine, which if somehow references the parent FutureTask again, it leads to StackOverflowError. This can happen in RxJava because AbstractDirectTask and ScheduledRunnable store the Future object returned by the executor in a reference field that gets accessed by their default toString implementation.

The fix is to define custom toStrings that break this cycle. Note that we can't print the underlying Runnable either because that could also reference something in a circular manner. In addition, the release of the runner Thread marker has been moved closer to the exit of the wrappers which helps with the state determination and self-cancellation.

To verify the fix works, a new GitHub Action has been added, targeting JDK 11 as the issue does not manifest itself under the main target JDK 8.

Resolves #7172

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@akarnokd akarnokd added this to the 3.1 milestone Jan 30, 2021
@codecov
Copy link

codecov bot commented Jan 30, 2021

Codecov Report

Merging #7173 (8156be7) into 3.x (8dd6f21) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #7173      +/-   ##
============================================
- Coverage     99.53%   99.51%   -0.02%     
- Complexity     6744     6749       +5     
============================================
  Files           747      747              
  Lines         47328    47350      +22     
  Branches       6360     6367       +7     
============================================
+ Hits          47107    47122      +15     
- Misses          101      103       +2     
- Partials        120      125       +5     
Impacted Files Coverage Δ Complexity Δ
...xjava3/internal/schedulers/AbstractDirectTask.java 100.00% <100.00%> (ø) 21.00 <4.00> (+4.00)
...ternal/schedulers/ScheduledDirectPeriodicTask.java 100.00% <100.00%> (ø) 2.00 <0.00> (ø)
...rxjava3/internal/schedulers/ScheduledRunnable.java 100.00% <100.00%> (ø) 35.00 <5.00> (+5.00)
...x/rxjava3/internal/operators/single/SingleAmb.java 96.61% <0.00%> (-3.39%) 9.00% <0.00%> (-1.00%)
.../operators/observable/ObservableFlatMapSingle.java 94.44% <0.00%> (-2.39%) 2.00% <0.00%> (ø%)
...nternal/operators/parallel/ParallelReduceFull.java 91.08% <0.00%> (-1.99%) 2.00% <0.00%> (ø%)
...ternal/operators/observable/ObservablePublish.java 97.29% <0.00%> (-1.81%) 16.00% <0.00%> (-1.00%)
...nternal/operators/observable/ObservableWindow.java 98.21% <0.00%> (-1.79%) 3.00% <0.00%> (ø%)
...ternal/operators/completable/CompletableMerge.java 97.29% <0.00%> (-1.36%) 2.00% <0.00%> (ø%)
...ernal/operators/flowable/FlowableFromIterable.java 98.95% <0.00%> (-1.05%) 5.00% <0.00%> (ø%)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dd6f21...2783b45. Read the comment docs.

@akarnokd
Copy link
Member Author

@akarnokd akarnokd merged commit 4d325c6 into ReactiveX:3.x Feb 1, 2021
@akarnokd akarnokd deleted the SchedulerFixToStringRecursion branch February 1, 2021 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.x StackOverflowError on prinln of Disposable returned from Scheduler
2 participants