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 Completable.concat to use replace (don't dispose old) #5695

Merged
merged 2 commits into from
Oct 31, 2017

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Oct 31, 2017

Completable.andThen, concat(Iterable) and concatArray() disposed the previous Disposable when receiving the new Disposable from the next source which could lead to interruption. concat(Publisher) already uses replace instead of update.

There is a peculiar interplay between subscribeOn, observeOn and the trampoline in concat which can trigger such an interruption: the task of the observeOn is cancelled with mayInterruptIfRunning == true because the dispose call chain shuts down the worker of the observeOn from the subscribeOn's thread.

Reported in #5694

@codecov
Copy link

codecov bot commented Oct 31, 2017

Codecov Report

Merging #5695 into 2.x will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##                2.x   #5695      +/-   ##
===========================================
+ Coverage     96.23%   96.3%   +0.07%     
  Complexity     5818    5818              
===========================================
  Files           634     634              
  Lines         41604   41604              
  Branches       5761    5761              
===========================================
+ Hits          40037   40067      +30     
+ Misses          628     610      -18     
+ Partials        939     927      -12
Impacted Files Coverage Δ Complexity Δ
.../operators/completable/CompletableConcatArray.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...erators/completable/CompletableConcatIterable.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...l/operators/observable/ObservableFlatMapMaybe.java 86.92% <0%> (-6.54%) 2% <0%> (ø)
...nternal/operators/parallel/ParallelSortedJoin.java 92.75% <0%> (-2.18%) 2% <0%> (ø)
...internal/operators/completable/CompletableAmb.java 98.3% <0%> (-1.7%) 11% <0%> (ø)
...ain/java/io/reactivex/subjects/UnicastSubject.java 97.51% <0%> (-1.25%) 64% <0%> (-1%)
...java/io/reactivex/processors/UnicastProcessor.java 94.73% <0%> (-1.17%) 63% <0%> (-1%)
...ernal/operators/flowable/FlowableFlatMapMaybe.java 94.2% <0%> (-0.97%) 2% <0%> (ø)
...internal/operators/flowable/FlowableSwitchMap.java 95.28% <0%> (-0.48%) 3% <0%> (ø)
...x/internal/operators/flowable/FlowablePublish.java 95.59% <0%> (-0.45%) 11% <0%> (ø)
... and 21 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 283ca57...9209efd. Read the comment docs.

for (int i = 0; i < count; i++) {
Completable.complete()
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io()) // The problem does not occur if you comment out this line
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete these comments?

try {
Thread.sleep(30);
} catch (InterruptedException e) {
System.out.println("Interrupted! " + Thread.currentThread()); // This is output periodically
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need it, or at least message should be changed to something like System.err.println("Interrupted, but was not expected to")

for (int k = 0; k < 100; k++) {
final int count = 10;
final CountDownLatch latch = new CountDownLatch(count);
final boolean[] interrupted = { false };
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: AtomicBoolean would be a nicer replacement for mutable Boolean :)

@akarnokd akarnokd merged commit 98ee8bc into ReactiveX:2.x Oct 31, 2017
@akarnokd akarnokd deleted the CompletableConcatUseReplace branch October 31, 2017 18:58
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 participants