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 cancel/dispose upon upstream switch for some operators #6258

Merged
merged 2 commits into from
Oct 27, 2018

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Oct 24, 2018

This PR extends the SubscriptionArbiter to optionally allow or disallow cancelling the current Subscription if it is replaced by a new one. Some operators do not need to cancel the current Subscription: concat, concatMap, repeat, repeatWhen, retry and retryWhen.

In addition repeatWhen and retryWhen were cancelling when the handler sequence itself terminated. The code has been updated to disconnect the upstream upon the completion/failure but before signaling the handler.

The Reactive Streams specification also disallows synchronous cancellation after the terminal event anyway.

Others may actually need to cancel, such as Timeout.

Observables don't have a specific arbiter, they use the DisposableHelper methods and the relevant ones were changed to replace() instead of the disposing set call.

Some tests actually checking if the dispose/cancel happens and had to be updated.

The Flowable.delaySubscription(Publisher) also used SubscriptionArbiter but it was unnecessary. The code has been replaced with a more apt deferred requesting scheme as the downstream requests need to be delayed until the main subscription happens, the other publisher is always consumed unbounded.

Resolves: #6259

@codecov
Copy link

codecov bot commented Oct 24, 2018

Codecov Report

Merging #6258 into 2.x will increase coverage by 0.05%.
The diff coverage is 96.55%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6258      +/-   ##
============================================
+ Coverage     98.22%   98.28%   +0.05%     
- Complexity     6203     6210       +7     
============================================
  Files           667      667              
  Lines         44889    44898       +9     
  Branches       6216     6219       +3     
============================================
+ Hits          44093    44126      +33     
+ Misses          254      242      -12     
+ Partials        542      530      -12
Impacted Files Coverage Δ Complexity Δ
...nal/operators/flowable/FlowableRetryPredicate.java 100% <100%> (ø) 2 <1> (ø) ⬇️
...l/operators/flowable/FlowableRetryBiPredicate.java 100% <100%> (ø) 2 <1> (ø) ⬇️
...nternal/operators/flowable/FlowableRepeatWhen.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...ternal/operators/flowable/FlowableRepeatUntil.java 100% <100%> (ø) 2 <1> (ø) ⬇️
...ex/internal/subscriptions/SubscriptionArbiter.java 100% <100%> (+2.54%) 51 <1> (+4) ⬆️
...ternal/operators/flowable/FlowableOnErrorNext.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...nal/operators/observable/ObservableRepeatWhen.java 98.43% <100%> (+0.02%) 2 <0> (ø) ⬇️
...ernal/operators/flowable/FlowableTimeoutTimed.java 98.37% <100%> (ø) 3 <0> (ø) ⬇️
...internal/operators/flowable/FlowableConcatMap.java 97.74% <100%> (-0.38%) 6 <0> (ø)
...rnal/operators/observable/ObservableRetryWhen.java 98.43% <100%> (+0.02%) 2 <0> (ø) ⬇️
... and 44 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 be0353c...465daea. Read the comment docs.

@artem-zinnatullin
Copy link
Contributor

David, can you please allow 2-3 days window for review on this one?
I'm smashed by work, but would really like to check this PR carefully

@akarnokd
Copy link
Member Author

Sure Artem.

child.onNext(t);
public void onNext(Object t) {
Subscription s = get();
if (s != SubscriptionHelper.CANCELLED) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offtopic: I'm wondering if we should drop SubscriptionHelper.isCancelled()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to inline all of them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarnokd akarnokd merged commit 1a774e6 into ReactiveX:2.x Oct 27, 2018
@akarnokd akarnokd deleted the ArbiterNoCancel branch October 27, 2018 21:08
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.

4 participants