Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OperatorConcat - prevent request overflow and fix race condition #2951

Merged
merged 1 commit into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/rx/internal/operators/OperatorConcat.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onStart() {
private void requestFromChild(long n) {
// we track 'requested' so we know whether we should subscribe the next or not
ConcatInnerSubscriber<T> actualSubscriber = currentSubscriber;
if (REQUESTED_UPDATER.getAndAdd(this, n) == 0) {
if (n > 0 && BackpressureUtils.getAndAddRequest(REQUESTED_UPDATER, this, n) == 0) {
if (actualSubscriber == null && wip > 0) {
// this means we may be moving from one subscriber to another after having stopped processing
// so need to kick off the subscribe via this request notification
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/rx/internal/operators/OperatorConcatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package rx.internal.operators;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
Expand All @@ -35,7 +36,9 @@
import org.mockito.InOrder;

import rx.Observable.OnSubscribe;
import rx.Scheduler.Worker;
import rx.*;
import rx.functions.Action0;
import rx.functions.Func1;
import rx.internal.util.RxRingBuffer;
import rx.observers.TestSubscriber;
Expand Down Expand Up @@ -766,4 +769,30 @@ public void onError(Throwable e) {

assertEquals(n, counter.get());
}

@Test
public void testRequestOverflowDoesNotStallStream() {
Observable<Integer> o1 = Observable.just(1,2,3);
Observable<Integer> o2 = Observable.just(4,5,6);
final AtomicBoolean completed = new AtomicBoolean(false);
o1.concatWith(o2).subscribe(new Subscriber<Integer>() {

@Override
public void onCompleted() {
completed.set(true);
}

@Override
public void onError(Throwable e) {

}

@Override
public void onNext(Integer t) {
request(2);
}});

assertTrue(completed.get());
}

}