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

3.x: Fix Flowable.flatMap not canceling the inner sources on outer error #6826

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ public void onError(Throwable t) {
}
if (errors.tryAddThrowableOrReport(t)) {
done = true;
if (!delayErrors) {
for (InnerSubscriber<?, ?> a : subscribers.getAndSet(CANCELLED)) {
a.dispose();
}
}
drain();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,4 +1116,38 @@ public Publisher<Integer> apply(Integer v) throws Throwable {
}
});
}

@Test
public void mainErrorsInnerCancelled() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();

pp1
.flatMap(v -> pp2)
.test();

pp1.onNext(1);
assertTrue("No subscribers?", pp2.hasSubscribers());

pp1.onError(new TestException());

assertFalse("Has subscribers?", pp2.hasSubscribers());
}

@Test
public void innerErrorsMainCancelled() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();

pp1
.flatMap(v -> pp2)
.test();

pp1.onNext(1);
assertTrue("No subscribers?", pp2.hasSubscribers());

pp2.onError(new TestException());

assertFalse("Has subscribers?", pp1.hasSubscribers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.*;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.*;
import io.reactivex.rxjava3.functions.*;
import io.reactivex.rxjava3.internal.functions.Functions;
Expand Down Expand Up @@ -1079,4 +1079,38 @@ public Observable<Integer> apply(Integer v) throws Throwable {
}
});
}

@Test
public void mainErrorsInnerCancelled() {
PublishSubject<Integer> ps1 = PublishSubject.create();
PublishSubject<Integer> ps2 = PublishSubject.create();

ps1
.flatMap(v -> ps2)
.test();

ps1.onNext(1);
assertTrue("No subscribers?", ps2.hasObservers());

ps1.onError(new TestException());

assertFalse("Has subscribers?", ps2.hasObservers());
}

@Test
public void innerErrorsMainCancelled() {
PublishSubject<Integer> ps1 = PublishSubject.create();
PublishSubject<Integer> ps2 = PublishSubject.create();

ps1
.flatMap(v -> ps2)
.test();

ps1.onNext(1);
assertTrue("No subscribers?", ps2.hasObservers());

ps2.onError(new TestException());

assertFalse("Has subscribers?", ps1.hasObservers());
}
}