From 5e62f80ba87cf9a902d24b435989b7d99ca7d88c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 10 Aug 2016 12:37:53 -0400 Subject: [PATCH] resetTransport: log all transient errors when they occur Previously, cancellation of the context would cause these transient errors to be swallowed since the function would return before the log line was reached. --- clientconn.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clientconn.go b/clientconn.go index 8d9d8d1c..abe82cb9 100644 --- a/clientconn.go +++ b/clientconn.go @@ -609,8 +609,7 @@ func (ac *addrConn) waitForStateChange(ctx context.Context, sourceState Connecti } func (ac *addrConn) resetTransport(closeTransport bool) error { - var retries int - for { + for retries := 0; ; retries++ { ac.mu.Lock() ac.printf("connecting") if ac.state == Shutdown { @@ -643,6 +642,7 @@ func (ac *addrConn) resetTransport(closeTransport bool) error { if e, ok := err.(transport.ConnectionError); ok && !e.Temporary() { return err } + grpclog.Printf("grpc: addrConn.resetTransport failed to create client transport: %v; Reconnecting to %q", err, ac.addr) ac.mu.Lock() if ac.state == Shutdown { // ac.tearDown(...) has been invoked. @@ -663,8 +663,6 @@ func (ac *addrConn) resetTransport(closeTransport bool) error { case <-ac.ctx.Done(): return ac.ctx.Err() } - retries++ - grpclog.Printf("grpc: addrConn.resetTransport failed to create client transport: %v; Reconnecting to %q", err, ac.addr) continue } ac.mu.Lock()