diff --git a/clientconn.go b/clientconn.go index be511f93..d6bf6d3e 100644 --- a/clientconn.go +++ b/clientconn.go @@ -868,11 +868,14 @@ func (ac *addrConn) resetTransport(closeTransport bool) error { } ac.mu.Unlock() closeTransport = false + timer := time.NewTimer(sleepTime - time.Since(connectTime)) select { - case <-time.After(sleepTime - time.Since(connectTime)): + case <-timer.C: case <-ac.ctx.Done(): + timer.Stop() return ac.ctx.Err() } + timer.Stop() continue } ac.mu.Lock() diff --git a/server.go b/server.go index 5a1d4ea1..f3c8f79d 100644 --- a/server.go +++ b/server.go @@ -445,10 +445,12 @@ func (s *Server) Serve(lis net.Listener) error { s.mu.Lock() s.printf("Accept error: %v; retrying in %v", err, tempDelay) s.mu.Unlock() + timer := time.NewTimer(tempDelay) select { - case <-time.After(tempDelay): + case <-timer.C: case <-s.ctx.Done(): } + timer.Stop() continue } s.mu.Lock()