Skip to content

Fix FlowableCache GC issue - #8249

Merged
akarnokd merged 1 commit into
ReactiveX:4.xfrom
DragonFSKY:issue-7912-flowable-cache-gc-4x
Jul 27, 2026
Merged

Fix FlowableCache GC issue#8249
akarnokd merged 1 commit into
ReactiveX:4.xfrom
DragonFSKY:issue-7912-flowable-cache-gc-4x

Conversation

@DragonFSKY

Copy link
Copy Markdown
Contributor

Summary

  • Split the source-facing state of FlowableCache into a static Multicaster.
  • Keep the cache head on the outer FlowableCache, while the upstream retains only the shared multicaster state and current tail.
  • Clear the multicaster tail on termination and guard against post-terminal signals.
  • Add a focused regression test verifying that consumed cached values become reclaimable.

Rationale

Previously, the upstream subscribed directly to the outer FlowableCache. This allowed the upstream connection to retain the outer cache and its head, keeping all cached nodes reachable even after application code could no longer create another subscription to that cache instance.

With the ownership split, the upstream retains only the static Multicaster. Once the outer FlowableCache becomes unreachable, consumed node prefixes can be reclaimed, while active subscribers continue to retain the suffix they still need.

The established behavior remains unchanged for valid upstream signals: the source is subscribed to at most once, the upstream is requested with Long.MAX_VALUE, each downstream keeps independent request accounting, replay remains serialized per downstream, and cancellation removes only that downstream without cancelling the shared upstream.

Validation

Local validation performed by the contributor:

  • Full FlowableCacheTest passed.
  • valuesAreReclaimable passed in five independent runs.
  • The same regression test failed against the unmodified 4.x implementation, with local heap usage increasing from approximately 8.2 MiB to 408.3 MiB.
  • checkstyleMain and checkstyleTest passed.
  • Validator tests passed.
  • ./gradlew build passed on Temurin 26.
  • Javadoc and git diff --check passed.

AI disclosure

I used an AI assistant to help analyze the FlowableCache retention graph, adapt the ownership-split approach to RxJava 4.x, and review the concurrency and regression-test implications.

I reviewed and decided the final implementation, performed the validation listed above, and am responsible for the code and submission.

References

@github-actions

Copy link
Copy Markdown

🐷 TruffleHog + Entropy Beauty Scan

Average entropy of changed code: 4.465 bits/char
Verdict: ✅ Mid-4 beauty detected (thoughtful human code!)

Changed files entropy:

src/main/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableCache.java: 4.226
src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableCacheTest.java: 4.703

✅ No secrets or suspicious high-entropy strings found.

Mid-4 beauty heuristic in action — powered by our entropy chats! 😊

@akarnokd akarnokd added this to the 4.0 milestone Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (47b6795) to head (1d277c9).

Additional details and impacted files
@@             Coverage Diff              @@
##                4.x    #8249      +/-   ##
============================================
- Coverage     98.64%   98.63%   -0.02%     
+ Complexity     7160     7125      -35     
============================================
  Files           822      822              
  Lines         50683    50690       +7     
  Branches       6889     6892       +3     
============================================
- Hits          49998    49996       -2     
- Misses          472      478       +6     
- Partials        213      216       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akarnokd
akarnokd merged commit f611947 into ReactiveX:4.x Jul 27, 2026
6 checks passed
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.

2 participants