🐛 fix: treat case for possible timer memory leak (#2488)

pull/2489/head
Lucas Lemos 2023-05-31 03:01:13 -03:00 committed by GitHub
parent 369494cf25
commit 5d53263572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -11,6 +11,9 @@ func Sleep(ctx context.Context, interval time.Duration) error {
var timer = time.NewTimer(interval)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
return ctx.Err()
case <-timer.C:
return nil