From b88929edf845a3f4ebc44941cda3bdf02c13a05e Mon Sep 17 00:00:00 2001 From: Uri Gorelik Date: Sat, 18 Nov 2023 08:33:47 -0500 Subject: [PATCH] Fix potential goroutine leak in syncs/watchdog.go Depending on how the preemption will occur, in some scenarios sendc would have blocked indefinitely even after cancelling the context. Fixes #10315 Signed-off-by: Uri Gorelik --- syncs/watchdog.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syncs/watchdog.go b/syncs/watchdog.go index f4042644d..6af07c53c 100644 --- a/syncs/watchdog.go +++ b/syncs/watchdog.go @@ -29,7 +29,10 @@ func Watch(ctx context.Context, mu sync.Locker, tick, max time.Duration) chan ti // Drop values written after c is closed. return } - c <- d + select { + case c <- d: + case <-ctx.Done(): + } } closec := func() { closemu.Lock()