Skip to content

Commit da0e548

Browse files
committed
Fix a deadlock in TransportSet.
Honor the lock order that transport lock > channel lock. Resolves #2246
1 parent 8628556 commit da0e548

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/src/main/java/io/grpc/internal/TransportSet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,14 @@ public void run() {
249249
delayedTransport.endBackoff();
250250
boolean shutdownDelayedTransport = false;
251251
Runnable runnable = null;
252+
// TransportSet as a channel layer class should not call into transport methods while
253+
// holding the lock, thus we call hasPendingStreams() outside of the lock. It will cause
254+
// a _benign_ race where the TransportSet may transition to CONNECTING when there is not
255+
// pending stream.
256+
boolean hasPendingStreams = delayedTransport.hasPendingStreams();
252257
synchronized (lock) {
253258
reconnectTask = null;
254-
if (delayedTransport.hasPendingStreams()) {
259+
if (hasPendingStreams) {
255260
// Transition directly to CONNECTING
256261
runnable = startNewTransport(delayedTransport);
257262
} else {

0 commit comments

Comments
 (0)