Skip to content

Commit

Permalink
Avoid 10 minute goroutine leak in error case for handled errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Liggitt <[email protected]>
  • Loading branch information
liggitt committed Jun 27, 2024
1 parent 0c1fc43 commit 5c84296
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,16 +740,14 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {

if err != nil {
duration := 10 * time.Minute
time.AfterFunc(duration, func() {
select {
case err, ok := <-s.shutdownChan:
if ok {
debugMessage("Unhandled close error after %s: %s", duration, err)
}
default:
}
})
s.shutdownChan <- err
timer := time.NewTimer(duration)
defer timer.Stop()
select {
case s.shutdownChan <- err:
// error was handled
case <-timer.C:
debugMessage("Unhandled close error after %s: %s", duration, err)
}
}
close(s.shutdownChan)
}
Expand Down

0 comments on commit 5c84296

Please sign in to comment.