Skip to content

Commit 0690c7c

Browse files
authored
3.x: Fix toFlowable(ERROR) not cancelling on MBE (#7083)
1 parent fe71f6a commit 0690c7c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableOnBackpressureError.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void onNext(T t) {
6565
downstream.onNext(t);
6666
BackpressureHelper.produced(this, 1);
6767
} else {
68+
upstream.cancel();
6869
onError(new MissingBackpressureException("could not emit value due to lack of requests"));
6970
}
7071
}

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableOnBackpressureErrorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313

1414
package io.reactivex.rxjava3.internal.operators.flowable;
1515

16+
import static org.junit.Assert.*;
17+
1618
import org.junit.Test;
1719
import org.reactivestreams.Publisher;
1820

1921
import io.reactivex.rxjava3.core.*;
22+
import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
2023
import io.reactivex.rxjava3.functions.Function;
24+
import io.reactivex.rxjava3.subjects.PublishSubject;
25+
import io.reactivex.rxjava3.subscribers.TestSubscriber;
2126
import io.reactivex.rxjava3.testsupport.TestHelper;
2227

2328
public class FlowableOnBackpressureErrorTest extends RxJavaTest {
@@ -51,4 +56,20 @@ public Object apply(Flowable<Integer> f) throws Exception {
5156
}
5257
}, false, 1, 1, 1);
5358
}
59+
60+
@Test
61+
public void overflowCancels() {
62+
PublishSubject<Integer> ps = PublishSubject.create();
63+
64+
TestSubscriber<Integer> ts = ps.toFlowable(BackpressureStrategy.ERROR)
65+
.test(0L);
66+
67+
assertTrue(ps.hasObservers());
68+
69+
ps.onNext(1);
70+
71+
assertFalse(ps.hasObservers());
72+
73+
ts.assertFailure(MissingBackpressureException.class);
74+
}
5475
}

0 commit comments

Comments
 (0)