From f8f4cd0944689bfc4d8cc39f6066e9c3c4660105 Mon Sep 17 00:00:00 2001 From: Dave Moten Date: Sun, 19 Apr 2015 22:01:43 +1000 Subject: [PATCH] fix race condition for range where two threads concurrently request Long.MAX_VALUE and both start the fast path thus possibly some items more than once --- src/main/java/rx/internal/operators/OnSubscribeRange.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/rx/internal/operators/OnSubscribeRange.java b/src/main/java/rx/internal/operators/OnSubscribeRange.java index f648e6f414..bcfbe0736b 100644 --- a/src/main/java/rx/internal/operators/OnSubscribeRange.java +++ b/src/main/java/rx/internal/operators/OnSubscribeRange.java @@ -55,12 +55,11 @@ private RangeProducer(Subscriber o, int start, int end) { @Override public void request(long n) { - if (REQUESTED_UPDATER.get(this) == Long.MAX_VALUE) { + if (requested == Long.MAX_VALUE) { // already started with fast-path return; } - if (n == Long.MAX_VALUE) { - REQUESTED_UPDATER.set(this, n); + if (n == Long.MAX_VALUE && REQUESTED_UPDATER.compareAndSet(this, 0, Long.MAX_VALUE)) { // fast-path without backpressure for (long i = index; i <= end; i++) { if (o.isUnsubscribed()) {