Skip to content

Commit aefdebb

Browse files
committed
Merge pull request #2892 from davidmoten/range-race
Fix Observable.range race condition
2 parents cbf8edf + f8f4cd0 commit aefdebb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ private RangeProducer(Subscriber<? super Integer> o, int start, int end) {
5555

5656
@Override
5757
public void request(long n) {
58-
if (REQUESTED_UPDATER.get(this) == Long.MAX_VALUE) {
58+
if (requested == Long.MAX_VALUE) {
5959
// already started with fast-path
6060
return;
6161
}
62-
if (n == Long.MAX_VALUE) {
63-
REQUESTED_UPDATER.set(this, n);
62+
if (n == Long.MAX_VALUE && REQUESTED_UPDATER.compareAndSet(this, 0, Long.MAX_VALUE)) {
6463
// fast-path without backpressure
6564
for (long i = index; i <= end; i++) {
6665
if (o.isUnsubscribed()) {

0 commit comments

Comments
 (0)