Fix exceeded() to fall back to configured interval when Retry-After is missing#28
Open
evan-burrell wants to merge 1 commit intosaloonphp:v2from
Open
Conversation
…igured interval When `exceeded()` is called without a `releaseInSeconds` value (e.g. when a 429 response has no Retry-After header), the expiry timestamp was not set explicitly. This caused it to be lazily calculated from "now" on each call to `getExpiryTimestamp()`, which can drift and lead to inconsistent state. Now `exceeded()` falls back to the limit's configured `releaseInSeconds` when no explicit value is provided, ensuring the expiry timestamp is always set deterministically at the moment the limit is exceeded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
Limit::exceeded()is called without areleaseInSecondsvalue (e.g. when a 429 response has noRetry-Afterheader), theexpiryTimestampwas not set explicitly. This caused it to be lazily recalculated from "now" on each call togetExpiryTimestamp(), which can drift and produce inconsistent state depending on when it's accessed.This change makes
exceeded()fall back to the limit's configuredreleaseInSecondsinterval when no explicit value is provided, ensuring the expiry timestamp is always set deterministically at the moment the limit is exceeded.Before
After
Changes
src/Limit.php: Inexceeded(), fall back to$this->releaseInSecondswhen$releaseInSecondsis nulltests/Unit/LimitTest.php: Added 3 tests covering the fallback behavior for regular limits, explicit values, and custom limitersTest plan
releaseInSecondsis nullreleaseInSecondsstill takes precedenceLimit::custom()defaults to 60s fallback