Skip to content

Commit

Permalink
fix incorrect usage of timer.Timer (#45846)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tigrato authored Aug 26, 2024
1 parent 187358d commit 957ef37
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/secretsscanner/authorizedkeys/authorized_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 957ef37

Please sign in to comment.