Skip to content
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

2.x: Fix publish().refCount() hang due to race #6505

Merged
merged 3 commits into from
Jun 20, 2019

Conversation

akarnokd
Copy link
Member

This PR adds a workaround implementation to the publish() implementations ObservablePublish and FlowablePublish so that when used with refCount, a connection-disconnection race won't leave consumers hanging in certain situations.

This was necessary to avoid the behavior change with the classic implementations used without refCount. In the alternate implementation, when the connectable terminates, the terminal event is signaled to late consumers until the operator is reset via the ResettableConnectable.

The refCount operator detects the classic implementations through the ObservablePublishClassic and FlowablePublishClassic internal interfaces and replaces them via the new implementations. The introduction of these interfaces were necessary to support 3rd party hooks that would intercept the classic connectable implementations via an arbitrary class which refCount wouldn't recognize or replace.

Fixes #6501

@akarnokd akarnokd added this to the 2.2 backlog milestone Jun 16, 2019
@codecov
Copy link

codecov bot commented Jun 16, 2019

Codecov Report

Merging #6505 into 2.x will decrease coverage by 0.02%.
The diff coverage is 96.59%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6505      +/-   ##
============================================
- Coverage     98.26%   98.23%   -0.03%     
- Complexity     6295     6329      +34     
============================================
  Files           675      677       +2     
  Lines         45163    45484     +321     
  Branches       6244     6318      +74     
============================================
+ Hits          44380    44683     +303     
- Misses          248      251       +3     
- Partials        535      550      +15
Impacted Files Coverage Δ Complexity Δ
...o/reactivex/observables/ConnectableObservable.java 100% <100%> (ø) 14 <3> (+2) ⬆️
...ternal/operators/observable/ObservablePublish.java 98.24% <100%> (+3.55%) 12 <1> (+1) ⬆️
...va/io/reactivex/flowables/ConnectableFlowable.java 100% <100%> (ø) 14 <3> (+2) ⬆️
...x/internal/operators/flowable/FlowablePublish.java 96.65% <100%> (+0.45%) 13 <2> (+3) ⬆️
...nal/operators/observable/ObservablePublishAlt.java 96.26% <96.26%> (ø) 15 <15> (?)
...nternal/operators/flowable/FlowablePublishAlt.java 96.5% <96.5%> (ø) 17 <17> (?)
...l/operators/observable/ObservableFlatMapMaybe.java 89.54% <0%> (-7.19%) 2% <0%> (ø)
...nternal/operators/parallel/ParallelReduceFull.java 91.08% <0%> (-3.97%) 2% <0%> (ø)
...tivex/internal/observers/FutureSingleObserver.java 94.33% <0%> (-3.78%) 24% <0%> (-1%)
...a/io/reactivex/internal/util/QueueDrainHelper.java 95.83% <0%> (-3.48%) 55% <0%> (-2%)
... and 28 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 89d506d...2626dd1. Read the comment docs.

@akarnokd akarnokd merged commit 19c0959 into ReactiveX:2.x Jun 20, 2019
@akarnokd akarnokd deleted the PublishRefCountRaceFix branch June 20, 2019 19:30
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.

publish().refCount() race may leave observers hanging
2 participants