Skip to content

Commit

Permalink
fix incorrect usage of timer.Timer
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 committed Aug 26, 2024
1 parent 50d50ed commit b35843f
Show file tree
Hide file tree
Showing 2 changed files with 5 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
1 change: 1 addition & 0 deletions mm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package mm

0 comments on commit b35843f

Please sign in to comment.