You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fix is trivial. In the inc() function, replace the > comparison with >=.
func (s*BurstSampler) inc() uint32 {
now:=TimestampFunc().UnixNano()
resetAt:=atomic.LoadInt64(&s.resetAt)
varcuint32ifnow>resetAt { // to be replaced by: if now >= resetAtc=1atomic.StoreUint32(&s.counter, c)
newResetAt:=now+s.Period.Nanoseconds()
reset:=atomic.CompareAndSwapInt64(&s.resetAt, resetAt, newResetAt)
if!reset {
// Lost the race with another goroutine trying to reset.c=atomic.AddUint32(&s.counter, 1)
}
} else {
c=atomic.AddUint32(&s.counter, 1)
}
returnc
}
If it's ok for you I open a PR with the fix and the unit test.
The text was updated successfully, but these errors were encountered:
crazy-pe
added a commit
to crazy-pe/zerolog
that referenced
this issue
Feb 26, 2025
Hello,
When mocking time for test purpose I found a bug in the reset condition of the burst sampler. Here is simple test to reproduce the bug:
The fix is trivial. In the
inc()
function, replace the>
comparison with>=
.If it's ok for you I open a PR with the fix and the unit test.
The text was updated successfully, but these errors were encountered: