From e975017b473bd9b2a3d5b23428a8549fe20b1153 Mon Sep 17 00:00:00 2001 From: mmukhi Date: Thu, 4 Jan 2018 11:16:47 -0800 Subject: [PATCH] Don't set reconnect parameters when the server has already responded. (#1779) --- clientconn.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/clientconn.go b/clientconn.go index 1d079eb2..bfbef362 100644 --- a/clientconn.go +++ b/clientconn.go @@ -1119,8 +1119,8 @@ func (ac *addrConn) createTransport(connectRetryNum, ridx int, backoffDeadline, } done := make(chan struct{}) onPrefaceReceipt := func() { - close(done) ac.mu.Lock() + close(done) if !ac.backoffDeadline.IsZero() { // If we haven't already started reconnecting to // other backends. @@ -1185,10 +1185,16 @@ func (ac *addrConn) createTransport(connectRetryNum, ridx int, backoffDeadline, close(ac.ready) ac.ready = nil } - ac.connectRetryNum = connectRetryNum - ac.backoffDeadline = backoffDeadline - ac.connectDeadline = connectDeadline - ac.reconnectIdx = i + 1 // Start reconnecting from the next backend in the list. + select { + case <-done: + // If the server has responded back with preface already, + // don't set the reconnect parameters. + default: + ac.connectRetryNum = connectRetryNum + ac.backoffDeadline = backoffDeadline + ac.connectDeadline = connectDeadline + ac.reconnectIdx = i + 1 // Start reconnecting from the next backend in the list. + } ac.mu.Unlock() return true, nil }