Repository navigation
feat: Add explicit concurrency control for new client - #3491
Conversation
|
👋 Hi, and thank you for this contribution! 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 joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
There was a problem hiding this comment.
Pull request overview
This PR adds explicit concurrency control to the new ghclient package by introducing a semaphore-based throttler that limits concurrent HTTP requests to 100 (matching GitHub's secondary rate limit maximum). It also improves the default HTTP transport configuration with explicit idle connection pool settings and reorders the transport middleware chain for better cache efficiency.
Changes:
- New
throttlerRoundTripper that uses a weighted semaphore to cap concurrent in-flight requests, releasing the semaphore only when the response body is closed. - Transport middleware ordering changed: cache is now outermost (avoiding network calls for cached responses), throttle sits between retry and rate-limit layers.
- Options struct simplified from pointer types to value types; connection pool settings (
maxIdleConns,idleConnTimeout) and the shared semaphore are set per source constructor.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/ghclient/throttle.go | New semaphore-based concurrency throttler with body-close-aware release |
| internal/ghclient/throttle_test.go | Thorough tests for throttler acquire/release semantics |
| internal/ghclient/transport.go | Updated transport chain: added throttle layer, moved cache to outermost, added connection pool config |
| internal/ghclient/transport_test.go | Test refactored to verify construction with various wrapper combinations (retry behavior no longer tested) |
| internal/ghclient/options.go | Options fields changed from pointers to values; added semaphore and conn pool fields |
| internal/ghclient/const.go | New constants for concurrency limit, idle connections, and timeouts |
| internal/ghclient/token.go | Source constructor now creates shared semaphore and temp cache dir |
| internal/ghclient/app.go | Same pattern as token source: shared semaphore, temp cache, per-client pool settings |
| internal/ghclient/anonymous.go | Same pattern as token source |
| internal/ghclient/cache.go | Simplified to require non-empty path; returns concrete *ghctbbolt.Storage |
| internal/ghclient/rest.go | URL options changed to value types; upload URL removed |
| internal/ghclient/graphql.go | Always uses NewEnterpriseClient with URL string |
| internal/ghclient/helpers_test.go | Added testOptions helper; updated test app source setup |
| internal/ghclient/*_test.go | Various tests updated to use testOptions(t) and table-driven patterns |
| github/provider.go | Provider config adapted to new value-type Options |
| github/config.go | CachePath changed from *string to string |
| go.mod | golang.org/x/sync promoted from indirect to direct dependency |
3acd34a to
06866ef
Compare
robert-crandall
left a comment
There was a problem hiding this comment.
Really like this - the per-source semaphore sized to the secondary rate limit is a clean way to bound concurrency, and moving the conditional cache to the outermost layer so cache hits don't burn a slot is a nice touch. I traced the body-close release path through the cache transport and it stays balanced, and the throttle tests cover it well. Builds and tests pass for me locally. Thanks for the thorough work here!
Signed-off-by: Steve Hipwell <[email protected]>
e8e442a to
6d475e8
Compare
deiga
left a comment
There was a problem hiding this comment.
Left a minor suggestion, no need to block merge for that
Resolves #ISSUE_NUMBER
Before the change?
After the change?
ghclientpackage has improved unit testsPull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!