Repository navigation
This release fixes three correctness bugs. The public API is unchanged.
Fixes
- Clock changes no longer stall the throttle. Time used to come from the wall clock (
time.Now().UnixMilli()). If the clock jumped back, for example from an NTP correction or a VM resuming, the throttle refused nearly every request until the clock caught up. It now uses the monotonic clock and reads it under the lock, so concurrent callers see time in the same order they update the counters. - Windows shorter than 1ms now work. The window used to be stored in whole milliseconds, so a window under 1ms became 0. That caused a divide by zero, which refused everything after the first fill on arm64 and admitted everything on amd64. Fractional windows were also rounded down. The window is now a
time.Durationwith nanosecond precision. A window of zero or less is treated as 1ns. AllowNandPeekNrefuse negative weights. A negative weight used to lower the counter, which let later operations exceed the limit.
Other
- The accuracy tests now run on simulated time, so they no longer fail when the machine is busy. New tests cover sub-millisecond windows, fractional windows and negative weights.
- The
Throttlestruct is now 72 bytes. The README has been updated to match.