Skip to content

Commit 057489c

Browse files
committed
chore: prevent resetAt and increaseAt from sliding backwards
1 parent 8491aba commit 057489c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/bucket.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ func (b *Bucket) Update(remaining, limit int64, resetAt, resetAfter float64, rat
227227
if ratelimitHit {
228228
// During ratelimit avoidance, we will treat the bucket as fixed
229229
// bucket and wait for it to fill up completely
230-
b.increaseAt = resetAtTime
231-
b.resetAt = resetAtTime
230+
if b.increaseAt.Before(resetAtTime) {
231+
b.increaseAt = resetAtTime
232+
}
233+
if b.resetAt.Before(resetAtTime) {
234+
b.resetAt = resetAtTime
235+
}
232236
b.remaining = 0
233237
b.outOfSync = false
234238
return
@@ -264,7 +268,9 @@ func (b *Bucket) Update(remaining, limit int64, resetAt, resetAfter float64, rat
264268
}
265269
}
266270

267-
b.resetAt = resetAtTime
271+
if b.resetAt.Before(resetAtTime) {
272+
b.resetAt = resetAtTime
273+
}
268274

269275
if b.outOfSync || firstValidHeaders {
270276
var period time.Duration

0 commit comments

Comments
 (0)