Skip to content

Commit

Permalink
Drain the timer's channel if needed, to prevent memory leakage
Browse files Browse the repository at this point in the history
When stopping a time.Timer, you need to check the return value and drain
the channel to prevent a memory leak, if the Timer has fired.
  • Loading branch information
lattwood committed Jun 14, 2024
1 parent 20a27f7 commit 9aa57cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ WAIT:
return 0, ErrTimeout
}
if timer != nil {
timer.Stop()
if !timer.Stop() {
<-timeout
}
}
goto START
}
Expand Down Expand Up @@ -234,7 +236,9 @@ WAIT:
return 0, ErrTimeout
}
if timer != nil {
timer.Stop()
if !timer.Stop() {
<-timeout
}
}
goto START
}
Expand Down

0 comments on commit 9aa57cd

Please sign in to comment.