Verify Short Sleep
ID |
go.verify_short_sleep |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Go |
Tags |
reliability, suspicious |
Description
Reports time.Sleep(n) called with a small bare integer literal that is not scaled by a time
duration constant.
Rationale
time.Sleep takes a time.Duration, which is a count of nanoseconds. So time.Sleep(5) sleeps
for five nanoseconds — almost never what the author intended. The correct form multiplies by a
unit constant, as in time.Sleep(5 * time.Second) or time.Sleep(200 * time.Millisecond).
time.Sleep(5) // FLAW — 5 nanoseconds; meant 5 * time.Second?
time.Sleep(5 * time.Second) // OK — scaled by a duration constant
time.Sleep(2000000000) // OK — large explicit nanosecond count
Parameters
maxBareLiteral-
Bare integer arguments below this value are flagged as a likely missing time unit. Defaults to
1000.
Remediation
Multiply the value by the intended unit constant from the time package
(time.Second, time.Millisecond, …).