Skip to content

[BUG]: Secondary rate limits are filed as primary ones, losing the rest of the hour #3660

Closed

Description

@benlangfeld

Expected Behavior

A secondary (burst) rate limit is backed off for the few seconds it asks to be waited out, and the run continues. The primary hourly quota — which has not been exhausted — stays usable.

Actual Behavior

One secondary rate limit ends the run. Every subsequent request in the same resource category is refused locally, without being sent, until the primary window resets up to an hour later:

Error: ... (http.RoundTripper).RoundTrip failed: primary rate limit reached on request to
https://api.github.com/... with category: core. wait until ... before sending more requests.

From a single terraform plan against an organisation of ~200 repositories, authenticated as a GitHub App installation (12,500 requests/hour):

288 identical errors, all timestamped within the same second, all citing the same reset ~9 minutes out

primary quota consumed across the entire run: 210 of 12,500  (1.7%)
  before   12,498 / 12,500
  after    12,288 / 12,500

A 12,500/hour primary limit cannot be exhausted by 210 requests. The run never came close to its primary budget. The 288-errors-in-one-second shape is not 288 rejections from GitHub — it is the category being armed once and every in-flight request being refused locally thereafter.

Root cause

Not in the provider. It is in github.com/gofri/go-github-ratelimit/v2 v2.0.2, wired up at internal/ghclient/transport.go:76.

GitHub sends x-ratelimit-remaining: 0 on some secondary rate limits, so the status code and that header together do not distinguish the two kinds of limit. Both of that library's limiters nevertheless decide on the header alone, from opposite directions:

  • the primary limiter arms the whole resource category for any 403/429 carrying remaining == 0, without reading the body;
  • the secondary detector returns early — commented // a primary rate limit — on that same header, before reading the body that would have identified it.

The secondary detector's deferral would be harmless if the primary limiter got it right, but github_ratelimit.New stacks the secondary limiter outside the primary one, so the primary inspects the response first, arms the category and returns an error. The secondary limiter never gets the turn the deferral assumed it would.

So a burst throttle asking for a few seconds' backoff is filed as an exhausted hourly quota, and the rest of the window is lost.

Upstream issue: gofri/go-github-ratelimit#50 — fix proposed in gofri/go-github-ratelimit#51 (makes the response body, rather than the header, decide which limit it is, on both sides).

What the provider needs to do once the fix is available

Bump github.com/gofri/go-github-ratelimit/v2 past the release carrying gofri/go-github-ratelimit#51. No provider code change — internal/ghclient/transport.go already passes the responses through both limiters correctly; they were classifying them wrongly.

Two things worth verifying with the bump, since this changes which limiter handles a response:

  1. secondaryRateLimitCallback will start firing for responses that previously fired primaryRateLimitCallback. That is the intended correction, but it means the tflog warnings change shape for anyone matching on them.
  2. A secondary limit carrying remaining: 0 and no retry-after has no usable backoff duration and is passed through to the caller as a bare 403 rather than waited out. That is a pre-existing gap in the library (the XXX in parseSecondaryLimitTime), not a new one, but it becomes reachable for this response shape. Worth a look once the bump lands.

Related but distinct: #3565 asks for the provider to wait for a primary reset rather than failing. That needs library support too — gofri/go-github-ratelimit#46, proposed in gofri/go-github-ratelimit#52 — and I have commented there with the details. The two are ordered: waiting is only safe once a primary limit actually means a primary limit, or a misclassified burst throttle turns a fail-fast into an hour-long sleep.

Terraform Version

Terraform v1.x, provider v6.13.0

GitHub Installation Type

GitHub App installation (app_auth), GitHub.com

Affected Resource(s)

All — this is in the shared HTTP transport, so any resource or data source can be the one that trips it.

Steps to Reproduce

Any plan or apply large enough to trigger GitHub's burst/secondary throttle. It needs concurrency rather than volume: ~200 repositories with several resources each was enough, well inside the primary budget.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. github-actions commented on Sep 30, 2026

    @github-actions

    👋 Hi, and thank you for opening this issue!

    This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

    You can help us prioritize by adding details, reproduction steps, or a 👍 to issues that matter to you, and by joining the discussion on open issues and PRs.


    🤖 This is an automated message.

  2. added
    Type: Bug
    on Oct 6, 2026
  3. added this to the v6.14.0 milestone on Oct 23, 2026
  4. stevehipwell commented on Oct 23, 2026

    @stevehipwell
    Collaborator

    @benlangfeld I've commented on the upstream PR as I think we need to fix this and then get a release out.

  5. benlangfeld commented on Nov 11, 2026

    @benlangfeld
    ContributorAuthor

    @stevehipwell I don't think that project is going to receive any maintenance. This provider probably needs to use a fork or something actively maintained.

  6. stevehipwell commented on Nov 12, 2026

    @stevehipwell
    Collaborator

    @benlangfeld I'm working on a replacement that integrates better with the other retry logic in the new client. We've also spotted that retry would fail on a HTTP/2 connection.

  7. stevehipwell commented on Nov 23, 2026

    @stevehipwell
    Collaborator

    @benlangfeld #3739 will fix this issue by replacing the rate limiting package with a custom implementation that integrates with the retry implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugUpstream

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions