From 2b099f266727ba2491589d7bf4ec043aa5ee9d03 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 9 Jul 2026 18:07:09 +0100 Subject: [PATCH] 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. --- backend/zoho/zoho.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/zoho/zoho.go b/backend/zoho/zoho.go index dc82965d0..28e0d6e13 100644 --- a/backend/zoho/zoho.go +++ b/backend/zoho/zoho.go @@ -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 }