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

Fix a concatMap race condition on inner and outer completions signals #1463

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private enum State {
private volatile State state = State.INIT;
private volatile Subscription upstream;
private Subscription currentUpstream;
private boolean upstreamHasCompleted = false;
private volatile boolean upstreamHasCompleted = false;
private Throwable failure;

private static final AtomicReferenceFieldUpdater<ConcatMapSubscriber, Subscription> UPSTREAM_UPDATER = AtomicReferenceFieldUpdater
Expand Down Expand Up @@ -148,10 +148,10 @@ private Throwable addFailure(Throwable failure) {

@Override
public void onCompletion() {
upstreamHasCompleted = true;
if (state == State.CANCELLED) {
return;
}
upstreamHasCompleted = true;
if (STATE_UPDATER.compareAndSet(this, State.WAITING_NEXT_PUBLISHER, State.CANCELLED)
|| STATE_UPDATER.compareAndSet(this, State.INIT, State.CANCELLED)) {
if (failure == null) {
Expand Down Expand Up @@ -243,18 +243,18 @@ public void onCompletion() {
if (state == State.CANCELLED) {
return;
}
if (!upstreamHasCompleted) {
state = State.WAITING_NEXT_PUBLISHER;
if (demand > 0L) {
upstream.request(1L);
}
} else {
state = State.CANCELLED;
state = State.WAITING_NEXT_PUBLISHER;
if (upstreamHasCompleted && STATE_UPDATER.compareAndSet(ConcatMapSubscriber.this, State.WAITING_NEXT_PUBLISHER,
State.CANCELLED)) {
if (failure != null) {
downstream.onFailure(failure);
} else {
downstream.onComplete();
}
} else {
if (demand > 0L) {
upstream.request(1L);
}
}
}

Expand Down