Skip to content

Commit

Permalink
Merge pull request #99 from liggitt/closeleak
Browse files Browse the repository at this point in the history
Avoid 10 minute goroutine leak in error case for handled errors
  • Loading branch information
dims authored Jun 27, 2024
2 parents 0c1fc43 + 5c84296 commit a3b79af
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 a3b79af

Please sign in to comment.