Skip to content

Commit

Permalink
Bugfix: deadline.Set() memory leak (issue #208)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
  • Loading branch information
floatingstatic authored and stv0g committed Nov 15, 2022
1 parent 4ce527f commit 7bbf06b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion deadline/deadline.go
Expand Up @@ -59,11 +59,15 @@ func (d *Deadline) Set(t time.Time) {
exceeded := d.exceeded
stopped := d.stopped
go func() {
timer := time.NewTimer(dur)
select {
case <-time.After(dur):
case <-timer.C:
close(exceeded)
stopped <- false
case <-d.stop:
if !timer.Stop() {
<-timer.C
}
stopped <- true
}
}()
Expand Down

0 comments on commit 7bbf06b

Please sign in to comment.