Skip to content

Commit

Permalink
fix a race
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Apr 9, 2020
1 parent 98515fc commit d3409df
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class ProxySubscriptionState extends SubscriptionState implements Subscriber<Con

private Subscription s;

private boolean cancelled = false;

ProxySubscriptionState(Publisher<? extends Connection> publisher) {
this.publisher = publisher;
}
Expand All @@ -123,14 +125,21 @@ public void request(long n) {
}

@Override
public void cancel() {
s.cancel();
public synchronized void cancel() {
cancelled = true;
if (s != null) {
s.cancel();
}
}

@Override
public void onSubscribe(Subscription s) {
public synchronized void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
if (!cancelled) {
s.request(1);
} else {
s.cancel();
}
}

@Override
Expand Down

0 comments on commit d3409df

Please sign in to comment.