Skip to content

timer-reset-drain-race

Detect attempts to drain a timer based on Reset's result.

Updated View as Markdown

Default severity: error

Using time.Timer.Reset’s boolean result to decide whether to receive from the timer channel is racy on older timer implementations and can block with current synchronous timer channels. Stop and drain before resetting when compatibility requires it, or reset without conditionally draining afterward.

Bad

if !timer.Reset(delay) { <-timer.C }

Good

if !timer.Stop() { select { case <-timer.C: default: } }
timer.Reset(delay)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close