Skip to content

Commit

Permalink
2.x: Fix concatMapSingle & concatMapMaybe dispose-cleanup crash (#5928)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Mar 23, 2018
1 parent 63572c7 commit 0fe6e55
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void cancel() {
cancelled = true;
upstream.cancel();
inner.dispose();
if (getAndIncrement() != 0) {
if (getAndIncrement() == 0) {
queue.clear();
item = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void cancel() {
cancelled = true;
upstream.cancel();
inner.dispose();
if (getAndIncrement() != 0) {
if (getAndIncrement() == 0) {
queue.clear();
item = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void dispose() {
cancelled = true;
upstream.dispose();
inner.dispose();
if (getAndIncrement() != 0) {
if (getAndIncrement() == 0) {
queue.clear();
item = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void dispose() {
cancelled = true;
upstream.dispose();
inner.dispose();
if (getAndIncrement() != 0) {
if (getAndIncrement() == 0) {
queue.clear();
item = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import io.reactivex.exceptions.*;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.Functions;
import io.reactivex.internal.operators.mixed.FlowableConcatMapMaybe.ConcatMapMaybeSubscriber;
import io.reactivex.internal.subscriptions.BooleanSubscription;
import io.reactivex.internal.util.ErrorMode;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.processors.PublishProcessor;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -368,4 +370,28 @@ public MaybeSource<? extends Object> apply(Integer v)

assertFalse(pp.hasSubscribers());
}

@Test(timeout = 10000)
public void cancelNoConcurrentClean() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ConcatMapMaybeSubscriber<Integer, Integer> operator =
new ConcatMapMaybeSubscriber<Integer, Integer>(
ts, Functions.justFunction(Maybe.<Integer>never()), 16, ErrorMode.IMMEDIATE);

operator.onSubscribe(new BooleanSubscription());

operator.queue.offer(1);

operator.getAndIncrement();

ts.cancel();

assertFalse(operator.queue.isEmpty());

operator.addAndGet(-2);

operator.cancel();

assertTrue(operator.queue.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import io.reactivex.exceptions.*;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.Functions;
import io.reactivex.internal.operators.mixed.FlowableConcatMapSingle.ConcatMapSingleSubscriber;
import io.reactivex.internal.subscriptions.BooleanSubscription;
import io.reactivex.internal.util.ErrorMode;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.processors.PublishProcessor;
import io.reactivex.subjects.SingleSubject;
Expand Down Expand Up @@ -283,4 +285,28 @@ public SingleSource<? extends Object> apply(Integer v)

assertFalse(pp.hasSubscribers());
}

@Test(timeout = 10000)
public void cancelNoConcurrentClean() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ConcatMapSingleSubscriber<Integer, Integer> operator =
new ConcatMapSingleSubscriber<Integer, Integer>(
ts, Functions.justFunction(Single.<Integer>never()), 16, ErrorMode.IMMEDIATE);

operator.onSubscribe(new BooleanSubscription());

operator.queue.offer(1);

operator.getAndIncrement();

ts.cancel();

assertFalse(operator.queue.isEmpty());

operator.addAndGet(-2);

operator.cancel();

assertTrue(operator.queue.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.reactivex.exceptions.*;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.Functions;
import io.reactivex.internal.operators.mixed.ObservableConcatMapMaybe.ConcatMapMaybeMainObserver;
import io.reactivex.internal.util.ErrorMode;
import io.reactivex.observers.TestObserver;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -373,4 +375,28 @@ public void scalarEmptySource() {

assertFalse(ms.hasObservers());
}

@Test(timeout = 10000)
public void cancelNoConcurrentClean() {
TestObserver<Integer> to = new TestObserver<Integer>();
ConcatMapMaybeMainObserver<Integer, Integer> operator =
new ConcatMapMaybeMainObserver<Integer, Integer>(
to, Functions.justFunction(Maybe.<Integer>never()), 16, ErrorMode.IMMEDIATE);

operator.onSubscribe(Disposables.empty());

operator.queue.offer(1);

operator.getAndIncrement();

to.dispose();

assertFalse(operator.queue.isEmpty());

operator.addAndGet(-2);

operator.dispose();

assertTrue(operator.queue.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.reactivex.exceptions.*;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.Functions;
import io.reactivex.internal.operators.mixed.ObservableConcatMapSingle.ConcatMapSingleMainObserver;
import io.reactivex.internal.util.ErrorMode;
import io.reactivex.observers.TestObserver;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.subjects.*;
Expand Down Expand Up @@ -310,4 +312,28 @@ public void scalarEmptySource() {

assertFalse(ss.hasObservers());
}

@Test(timeout = 10000)
public void cancelNoConcurrentClean() {
TestObserver<Integer> to = new TestObserver<Integer>();
ConcatMapSingleMainObserver<Integer, Integer> operator =
new ConcatMapSingleMainObserver<Integer, Integer>(
to, Functions.justFunction(Single.<Integer>never()), 16, ErrorMode.IMMEDIATE);

operator.onSubscribe(Disposables.empty());

operator.queue.offer(1);

operator.getAndIncrement();

to.cancel();

assertFalse(operator.queue.isEmpty());

operator.addAndGet(-2);

operator.dispose();

assertTrue(operator.queue.isEmpty());
}
}

0 comments on commit 0fe6e55

Please sign in to comment.