From aec8eded542a56b2cccf4ebd3d9ee727e2f1a260 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 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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))