Skip to content

Commit

Permalink
pubsub: fix potential deadlock in startConnections (#1674)
Browse files Browse the repository at this point in the history
If a subscriber connection fails, awaitRunning will throw
IllegalStateException.
We must make sure that we count down the latch in either case;
otherwise startup will deadlock.

Also move the call to addListener above startAsync.
Otherwise, the listener might not see the connection failing
if it fails too quickly.
  • Loading branch information
pongad authored Mar 8, 2017
1 parent 33d824d commit a32c41a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public boolean isRunning() {
* }
* }, executor);
* subscriber.startAsync();
*
*
* // Wait for a stop signal.
* done.get();
* subscriber.stopAsync().awaitTerminated();
Expand Down Expand Up @@ -466,9 +466,12 @@ private void startConnections(
new Runnable() {
@Override
public void run() {
subscriber.startAsync().awaitRunning();
subscribersStarting.countDown();
subscriber.addListener(connectionsListener, executor);
try {
subscriber.startAsync().awaitRunning();
} finally {
subscribersStarting.countDown();
}
}
});
}
Expand Down

0 comments on commit a32c41a

Please sign in to comment.