zoho: fix flaky folder list limiter test under concurrent listings
The folder list limiter granted the caller-supplied time immediately in the burst phase, so concurrent callers observing time.Now() out of order could record grant times that moved backwards. The sliding safety log indexes grants as an ordered history, so out-of-order grants could also breach the rolling-window cap. Clamp each grant to be at or after the previous one so grant times are always monotonic.
This commit is contained in:
@@ -447,6 +447,12 @@ const folderListSafetyMargin = 500 * time.Millisecond
|
||||
func (l *folderWindowLimiter) reserve(now time.Time) time.Time {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
// Never let a grant move backwards, even if concurrent callers observe
|
||||
// time.Now() out of order: the sliding safety log below indexes grants as
|
||||
// an ordered history, so out-of-order grant times would corrupt the cap.
|
||||
if now.Before(l.lastGrant) {
|
||||
now = l.lastGrant
|
||||
}
|
||||
if l.windowStart.IsZero() {
|
||||
l.windowStart = now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user