Skip to content

Commit

Permalink
Avoid leaking timeout timer channels
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Liggitt <[email protected]>
  • Loading branch information
liggitt committed Jun 28, 2024
1 parent 258380d commit ad82e28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {

var timeout <-chan time.Time
if closeTimeout > time.Duration(0) {
timeout = time.After(closeTimeout)
timer := time.NewTimer(closeTimeout)
defer timer.Stop()
timeout = timer.C
}
streamsClosed := make(chan bool)

Expand Down Expand Up @@ -806,7 +808,9 @@ func (s *Connection) CloseWait() error {
func (s *Connection) Wait(waitTimeout time.Duration) error {
var timeout <-chan time.Time
if waitTimeout > time.Duration(0) {
timeout = time.After(waitTimeout)
timer := time.NewTimer(waitTimeout)
defer timer.Stop()
timeout = timer.C
}

select {
Expand Down

0 comments on commit ad82e28

Please sign in to comment.