Repository navigation
Conversation
x-ratelimit-reset is the primary rate limit's reset, which can be up to an hour away. GitHub's docs only use it for a secondary limit when x-ratelimit-remaining is 0; otherwise they ask to wait at least one minute. Sleeping until x-ratelimit-reset blocked every request through the limiter for up to an hour while the primary quota was mostly unused.
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.
When a secondary rate limit response has no
retry-afterheader, the limiter sleeps untilx-ratelimit-reset. That header is the reset of the primary rate limit window, which can be up to an hour away, so every request through the limiter blocks for up to an hour.GitHub's docs (Exceeding the rate limit) use
x-ratelimit-resetfor a secondary limit only whenx-ratelimit-remainingis0:This limiter never handles that case: a response with
x-ratelimit-remaining: 0is treated as a primary limit and passed through (see #50). So thex-ratelimit-resetfallback only runs when quota remains, which is exactly when the docs say to wait a minute instead. This is the long backoff reported in #38, and the first part of #29.Seen in production
Atlantis wraps all its GitHub calls in
NewSecondaryLimiter(v2.0.2). After a burst of about 80 PR comments in one minute, every GitHub request from the server stopped for 32 minutes. When the wait ended, the queued requests went out together and the server stopped again, this time for a full hour. The two wake-ups were exactly an hour apart, matching the primary window's reset. For about 90 minutes the server couldn't run comment commands, post comments or set commit statuses.The change
retry-after, sleep one minute instead of untilx-ratelimit-reset.parseXRateLimitResethad no other caller and is removed.HeaderXRateLimitResetstays exported.TestXRateLimitasserted the old behavior.TestXRateLimitResetIgnoredreplaces it: it injects a reset 30 minutes away and checks that the computed sleep is one minute. A zeroWithSingleSleepLimitreads the sleep without waiting it out.Not included: the exponential backoff the docs suggest if the limit persists. Callers can still bound waits with
WithSingleSleepLimitandWithTotalSleepLimit.With #51
#51 lets secondary limits with
x-ratelimit-remaining: 0reach this function, and notes that withoutretry-afterthey are passed through unwaited. With this change they would wait one minute. Both PRs editparseXRateLimitReset; whichever lands second resolves to removing it.Testing
go test ./...andgolangci-lintv1.64.6 on Go 1.23.1, the versions CI uses.