Skip to content

Rate-limit pacing runs inside each of the 5 concurrent request slots, so requests go out up to 5× faster than paced #341

Open

Description

@matt-edmondson

What's wrong

MakeGitHubRequestAsync (BuildMonitor/Providers/GitHub.cs ~L689-L708) first takes a RequestSemaphore slot, then waits GetRateLimitWaitTime() with Task.Delay. MakeAzureDevOpsRequestAsync (BuildMonitor/Providers/AzureDevOps.cs ~L403-L411) does the same.

The semaphore allows 5 holders (BuildProvider.cs ~L191-L196). Up to 5 requests therefore wait out the same delay at the same time and are sent together.

The delay is meant to be the gap between requests:

  • BaseRequestDelay is documented as the "Base delay between requests".
  • CalculateAdaptivePacing spreads the remaining budget evenly over the window, at timeUntilReset / usableBudget * 1.1 per request.

With all 5 slots busy, the real rate is about 5 / delay instead of 1 / delay.

Repro (scratch MSTest with an in-memory TokenStorage, as in GitHubRequestOutcomeTests)

GitHub provider = new();
var sw = Stopwatch.StartNew();
await Task.WhenAll(Enumerable.Range(0, 10).Select(i => provider.MakeGitHubRequestAsync($"r{i}", () => Task.CompletedTask)));
// elapsed ≈ 1075 ms; with a 500 ms gap between requests, 10 requests should take ≥ ~4.5 s

Failure scenario

  1. An org has ~80 repositories with 3–4 workflows each, about 300 builds.
  2. Low-priority polling (every 120 s) wants ~2.5 requests/s. The token allows 5,000 requests per hour.
  3. With 4,500 requests left and 3,600 s to reset, pacing works out to ~0.9 s per request, which should hold the rate near 1.1/s.
  4. Because 5 slots wait in parallel, ~5.5 requests/s actually go out.
  5. The budget falls through the 15% and 5% gates within minutes, and polling degrades to High priority only.

Suggested fix

  • Pace with a single provider-wide "next request allowed at" timestamp, shared by all callers and protected by a lock or Interlocked.
  • Each request reserves max(now, next) and moves next forward by the paced delay.
  • Keep the semaphore only as a concurrency cap.
  • Don't hold a semaphore slot while waiting for a rate-limit reset, or make that one shared wait.

Acceptance criteria

  • N concurrent MakeGitHubRequestAsync calls with no-op actions take at least (N-1) × BaseRequestDelay.
  • The same holds for adaptive pacing with an injected budget.
  • The Azure DevOps path behaves the same way.

This is not #331 (per-token budgets) or #333 (stale budget after reset). It happens with a single token and a correct budget.

Activity

  1. added
    bug
    on Oct 6, 2026
  2. matt-edmondson commented on Oct 6, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions