Skip to content

Commit e975017

Browse files
authored
Don't set reconnect parameters when the server has already responded. (grpc#1779)
1 parent 7aea499 commit e975017

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

clientconn.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,8 @@ func (ac *addrConn) createTransport(connectRetryNum, ridx int, backoffDeadline,
11191119
}
11201120
done := make(chan struct{})
11211121
onPrefaceReceipt := func() {
1122-
close(done)
11231122
ac.mu.Lock()
1123+
close(done)
11241124
if !ac.backoffDeadline.IsZero() {
11251125
// If we haven't already started reconnecting to
11261126
// other backends.
@@ -1185,10 +1185,16 @@ func (ac *addrConn) createTransport(connectRetryNum, ridx int, backoffDeadline,
11851185
close(ac.ready)
11861186
ac.ready = nil
11871187
}
1188-
ac.connectRetryNum = connectRetryNum
1189-
ac.backoffDeadline = backoffDeadline
1190-
ac.connectDeadline = connectDeadline
1191-
ac.reconnectIdx = i + 1 // Start reconnecting from the next backend in the list.
1188+
select {
1189+
case <-done:
1190+
// If the server has responded back with preface already,
1191+
// don't set the reconnect parameters.
1192+
default:
1193+
ac.connectRetryNum = connectRetryNum
1194+
ac.backoffDeadline = backoffDeadline
1195+
ac.connectDeadline = connectDeadline
1196+
ac.reconnectIdx = i + 1 // Start reconnecting from the next backend in the list.
1197+
}
11921198
ac.mu.Unlock()
11931199
return true, nil
11941200
}

0 commit comments

Comments
 (0)