Merge pull request #1475 from shirou/feature/fix_potential_leak_on_common_sleep

[common]: fix potential leak on Sleep.
This commit is contained in:
shirou 2023-05-29 22:56:32 +09:00 committed by GitHub
commit 32e8a92ad6
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 {
timer := time.NewTimer(interval) timer := time.NewTimer(interval)
select { select {
case <-ctx.Done(): case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
return ctx.Err() return ctx.Err()
case <-timer.C: case <-timer.C:
return nil return nil