mirror of
https://github.com/rclone/rclone.git
synced 2026-02-11 14:03:46 +00:00
pacer: re-read the sleep time as it may be stale
Before this change we read sleepTime before acquiring the pacer token and uses that possibly stale value to schedule the token return. When many goroutines enter while sleepTime is high (e.g., 10s), each goroutine caches this 10s value. Even if successful calls rapidly decay the pacer state to 0, the queued goroutines still schedule 10s token returns, so the queue drains at 1 req/10s for the entire herd. This can create multi‑minute delays even after the pacer has dropped to 0. After this change we refresh the sleep time after getting the token. This problem was introduced by the desire to skip reading the pacer token entirely when sleepTime is 0 in high performance backends (eg s3, azure blob).
This commit is contained in:
@@ -168,6 +168,12 @@ func (p *Pacer) beginCall(limitConnections bool) {
|
||||
if sleepTime > 0 {
|
||||
<-p.pacer
|
||||
|
||||
// Re-read the sleep time as it may be stale
|
||||
// after waiting for the pacer token
|
||||
p.mu.Lock()
|
||||
sleepTime = p.state.SleepTime
|
||||
p.mu.Unlock()
|
||||
|
||||
// Restart the timer
|
||||
go func(t time.Duration) {
|
||||
time.Sleep(t)
|
||||
|
||||
Reference in New Issue
Block a user