From 7f43deae474886e803e8f7d2ae4d52b653d7bccb Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 18 Jul 2017 17:43:03 -0700 Subject: [PATCH] refactor transportMonitor t.error case --- clientconn.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/clientconn.go b/clientconn.go index 4bda21c56cc3..6d9a9b64ca03 100644 --- a/clientconn.go +++ b/clientconn.go @@ -949,28 +949,22 @@ func (ac *addrConn) transportMonitor() { ac.adjustParams(t.GetGoAwayReason()) // If GoAway happens without any network I/O error, the underlying transport // will be gracefully closed, and a new transport will be created. - // (the transport will be closed when all the pending RPCs finished or failed.). + // (the transport will be closed when all the pending RPCs finished or failed.) // If GoAway and some network I/O error happen concurrently, the underlying transport // will be closed, and a new transport will be created. + var drain bool select { case <-t.Error(): - if err := ac.resetTransport(false); err != nil { - grpclog.Infof("get error from resetTransport %v, transportMonitor returning", err) - if err != errConnClosing { - // Keep this ac in cc.conns, to get the reason it's torn down. - ac.tearDown(err) - } - return - } default: - if err := ac.resetTransport(true); err != nil { - grpclog.Infof("get error from resetTransport %v, transportMonitor returning", err) - if err != errConnClosing { - // Keep this ac in cc.conns, to get the reason it's torn down. - ac.tearDown(err) - } - return + drain = true + } + if err := ac.resetTransport(drain); err != nil { + grpclog.Infof("get error from resetTransport %v, transportMonitor returning", err) + if err != errConnClosing { + // Keep this ac in cc.conns, to get the reason it's torn down. + ac.tearDown(err) } + return } case <-t.Error(): select {