clientconn, server: replace time.After with time.NewTimer (#998)
When timeout is not hit `time.After` will leak unnecessary timer, so it's better to stop timer explicitly. Signed-off-by: Alexander Morozov <lk4d4math@gmail.com>
This commit is contained in:
Родитель
c7379be7b6
Коммит
9bf8ea0a82
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче