Skip to content

Commit 338f2a1

Browse files
authored
Update BlockingFlowableIterable.onNext() to set error before cancel (#7789)
To avoid race with hasNext(), which checks for cancel first before checking for error. For example, in the following case, hasNext() may return false to the caller, making the caller assume the iterable finished successfully. 1. onNext() called cancel 2. hasNext() found the iterable is cancelled 3. hasNext() found that error is null thus returned false to the caller, without throwing the error 4. onNext() set error
1 parent e46ea36 commit 338f2a1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: src/main/java/io/reactivex/rxjava3/internal/operators/flowable/BlockingFlowableIterable.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ public void onSubscribe(Subscription s) {
138138
@Override
139139
public void onNext(T t) {
140140
if (!queue.offer(t)) {
141+
// Error must be set first before calling cancel to avoid race
142+
// with hasNext(), which checks for cancel first before checking
143+
// for error.
144+
error = new QueueOverflowException();
141145
SubscriptionHelper.cancel(this);
142-
143-
onError(new QueueOverflowException());
146+
onComplete();
144147
} else {
145148
signalConsumer();
146149
}

0 commit comments

Comments
 (0)