Skip to content

Commit

Permalink
Fix a deadlock in TransportSet.
Browse files Browse the repository at this point in the history
Honor the lock order that transport lock > channel lock.

Resolves #2246
  • Loading branch information
zhangkun83 committed Sep 13, 2016
1 parent 8628556 commit da0e548
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/main/java/io/grpc/internal/TransportSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,14 @@ public void run() {
delayedTransport.endBackoff();
boolean shutdownDelayedTransport = false;
Runnable runnable = null;
// TransportSet as a channel layer class should not call into transport methods while
// holding the lock, thus we call hasPendingStreams() outside of the lock. It will cause
// a _benign_ race where the TransportSet may transition to CONNECTING when there is not
// pending stream.
boolean hasPendingStreams = delayedTransport.hasPendingStreams();
synchronized (lock) {
reconnectTask = null;
if (delayedTransport.hasPendingStreams()) {
if (hasPendingStreams) {
// Transition directly to CONNECTING
runnable = startNewTransport(delayedTransport);
} else {
Expand Down

0 comments on commit da0e548

Please sign in to comment.