Skip to content

[12.x] Fix infinite rate limiter TTL on custom increments#59693

Merged
taylorotwell merged 3 commits intolaravel:12.xfrom
paulandroshchuk:fix-rate-limiter
Apr 15, 2026
Merged

[12.x] Fix infinite rate limiter TTL on custom increments#59693
taylorotwell merged 3 commits intolaravel:12.xfrom
paulandroshchuk:fix-rate-limiter

Conversation

@paulandroshchuk
Copy link
Copy Markdown
Contributor

@paulandroshchuk paulandroshchuk commented Apr 14, 2026

This fixes a race condition in RateLimiter::increment() when the increment $amount is greater than 1.

If the counter key disappears after Laravel checks for it but before the increment() happens, the cache can recreate that key during increment(). When that happens, Laravel needs to write the value back with the proper decay time so the key does not live forever.

The bug was that this recovery logic only checked for == 1. That works for the default increment, but not for calls like increment(..., 5), where the recreated value is 5. This change checks against $amount instead, so custom increments also get the correct TTL.

See #20684 for additional context.

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@paulandroshchuk paulandroshchuk changed the title Fix rate limiter's increment with custom $amount Fix rate limiter cache leak with custom $amount Apr 14, 2026
@paulandroshchuk paulandroshchuk marked this pull request as ready for review April 15, 2026 06:49
@paulandroshchuk paulandroshchuk changed the title Fix rate limiter cache leak with custom $amount [12.x] Fix rate limiter cache leak with custom $amount Apr 15, 2026
@paulandroshchuk paulandroshchuk changed the title [12.x] Fix rate limiter cache leak with custom $amount [12.x] Fix infinite rate limiter TTL on custom increments Apr 15, 2026
@taylorotwell taylorotwell merged commit 68b2b02 into laravel:12.x Apr 15, 2026
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants