Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.resource-leak

Avoid time.Tick for stoppable timers

time.Tick leaks the underlying ticker because it cannot be stopped.

#Metadata

Rule ID
go.correctness.time-tick-leak
Severity
medium
Confidence
0.9
Languages
go
Presets
strict
Stability
stable
Applies to
block
Tags
correctness, go, rules-catalog

#Why it matters

`time.Tick` is documented as appropriate only for cases that run forever. Use `time.NewTicker` so the ticker can be `Stop`ped when the consumer is done with it.

#Remediation

Replace `time.Tick(d)` with `time.NewTicker(d)` and defer `ticker.Stop()` once the consumer no longer needs the channel.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/go/go.correctness.time-tick-leak.rule.yaml.