Skip to content

Commit 9d90aed

Browse files
committed
Merge pull request ReactiveX#2895 from davidmoten/from-iter-race
Fix Observable.from(Iterable) race condition
2 parents aefdebb + adaa913 commit 9d90aed

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/rx/internal/operators/OnSubscribeFromIterable.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ private IterableProducer(Subscriber<? super T> o, Iterator<? extends T> it) {
6262

6363
@Override
6464
public void request(long n) {
65-
if (REQUESTED_UPDATER.get(this) == Long.MAX_VALUE) {
65+
if (requested == Long.MAX_VALUE) {
6666
// already started with fast-path
6767
return;
6868
}
69-
if (n == Long.MAX_VALUE) {
70-
REQUESTED_UPDATER.set(this, n);
69+
if (n == Long.MAX_VALUE && REQUESTED_UPDATER.compareAndSet(this, 0, Long.MAX_VALUE)) {
7170
// fast-path without backpressure
7271
while (it.hasNext()) {
7372
if (o.isUnsubscribed()) {
@@ -78,7 +77,7 @@ public void request(long n) {
7877
if (!o.isUnsubscribed()) {
7978
o.onCompleted();
8079
}
81-
} else if(n > 0) {
80+
} else if (n > 0) {
8281
// backpressure is requested
8382
long _c = BackpressureUtils.getAndAddRequest(REQUESTED_UPDATER, this, n);
8483
if (_c == 0) {

0 commit comments

Comments
 (0)