Skip to content

fix: Simplify new client throttle logic to avoid leaks - #3605

Open
stevehipwell wants to merge 2 commits into
mainfrom
stevehipwell/new-client-throttle-refactor
Open

fix: Simplify new client throttle logic to avoid leaks#3605
stevehipwell wants to merge 2 commits into
mainfrom
stevehipwell/new-client-throttle-refactor

Conversation

@stevehipwell

Copy link
Copy Markdown
Collaborator

Resolves #3603


Before the change?

  • New client would leak concurrency permits
  • New client concurrency constraint based on reading the response body

After the change?

  • New client concurrency permits can't leak
  • New client concurrency constraint based on remote processing

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.14.0 milestone Aug 12, 2026
@stevehipwell
stevehipwell requested a review from deiga August 12, 2026 10:08
@stevehipwell stevehipwell self-assigned this Aug 12, 2026
@stevehipwell stevehipwell added the Type: Bug Something isn't working as documented label Aug 12, 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.

Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
@stevehipwell
stevehipwell force-pushed the stevehipwell/new-client-throttle-refactor branch from 44fec94 to 2272db0 Compare August 12, 2026 10:17
@deiga
deiga requested a balanced review from Copilot August 12, 2026 18:36

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

These provider review instructions are being used.

MEDIUM — Missing targeted regression coverage
internal/ghclient/throttle_test.go:109: The new concurrency test also passes with the leaking implementation. Add the client-level 404 regression from issue #3603.

This PR releases concurrency permits when remote processing completes rather than when response bodies close.

Changes:

  • Simplifies semaphore release logic.
  • Adds concurrent throttling tests and test helpers.

Reviewed changes

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

File Description
internal/ghclient/throttle.go Releases permits after RoundTrip.
internal/ghclient/throttle_test.go Updates throttling tests.
internal/ghclient/helpers_test.go Adds delay and request helpers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/ghclient/throttle_test.go
deiga
deiga previously approved these changes Aug 12, 2026

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

Looks good, but I can't fully vouch for the functionality. This isn't my strongest area 😬

Comment thread internal/ghclient/helpers_test.go Outdated

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 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

internal/ghclient/throttle_test.go:113

  • This does not cover the reported regression: the inner transport returns an error and no response, so the previous implementation's explicit error-path release would also pass. Return a successful non-2xx response and deliberately leave its body unclosed; then TryAcquire will fail against the old body-close-based implementation and prove this fix prevents the leak.
		inner := &testRoundTripper{err: errors.New("boom")}
		sema := semaphore.NewWeighted(1)

@stevehipwell stevehipwell added the needs-github-review Request a review from GitHub label Aug 13, 2026
@team-review-router
team-review-router Bot requested a review from a team August 13, 2026 13:57

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

Nice cleanup — dropping the throttlerReadCloser in favor of a plain defer Release makes the leak impossible by construction, and moving the constraint to remote processing time feels like the right semantics here. Thanks for tracking this down!

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

Labels

needs-github-review Request a review from GitHub Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: New client leaks concurrency permits on non-2xx REST responses

4 participants