From b35843fad1e4d0980f1e1a2b04079049155b07de Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Mon, 26 Aug 2024 16:12:22 +0100 Subject: [PATCH] fix incorrect usage of `timer.Timer` Calling `timer.Stop` in a timer that already fired results in `Stop` returning false and subsequent drain will block because the channel isn't closed. This PR fixes the drain behaviour by wrapping the drain operation in a non-blocking select. --- lib/secretsscanner/authorizedkeys/authorized_keys.go | 5 ++++- mm/main.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 mm/main.go diff --git a/lib/secretsscanner/authorizedkeys/authorized_keys.go b/lib/secretsscanner/authorizedkeys/authorized_keys.go index ae6e2adb1b8c8..c3472492af21c 100644 --- a/lib/secretsscanner/authorizedkeys/authorized_keys.go +++ b/lib/secretsscanner/authorizedkeys/authorized_keys.go @@ -210,7 +210,10 @@ func (w *Watcher) start(ctx context.Context) error { } if !timer.Stop() { - <-timer.Chan() + select { + case <-timer.Chan(): + default: + } } timer.Reset(jitterFunc(maxReSendInterval)) diff --git a/mm/main.go b/mm/main.go new file mode 100644 index 0000000000000..ccfa42db295dd --- /dev/null +++ b/mm/main.go @@ -0,0 +1 @@ +package mm