Skip to content

feat: Add explicit concurrency control for new client - #3491

Merged
stevehipwell merged 4 commits into
integrations:mainfrom
stevehipwell:client-concurrency
Jun 18, 2026
Merged

stevehipwell merged 4 commits into
integrations:mainfrom
stevehipwell:client-concurrency

Conversation

@stevehipwell

@stevehipwell stevehipwell commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Resolves #ISSUE_NUMBER


Before the change?

After the change?

  • The new client has explicit concurrency control to limit cross client request concurrency to the secondary rate limit
  • The new client has improved default transport options
  • The new client has a user agent with the provider version
  • The ghclient package has improved unit tests

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@stevehipwell stevehipwell added this to the v6.13.0 milestone Jun 16, 2026
@stevehipwell stevehipwell self-assigned this Jun 16, 2026
@stevehipwell stevehipwell added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Jun 16, 2026
@github-actions

Copy link
Copy Markdown

👋 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 throttler RoundTripper 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

Comment thread internal/ghclient/transport_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Comment thread internal/ghclient/transport_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.

@robert-crandall robert-crandall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor suggestion, no need to block merge for that

Comment thread internal/ghclient/options.go Resolved
@stevehipwell
stevehipwell merged commit 07c3472 into integrations:main Jun 18, 2026
10 checks passed
@stevehipwell
stevehipwell deleted the client-concurrency branch June 18, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants