Repository navigation
fix: respect context cancellation in RetryTransport - #3383
stevehipwell merged 2 commits into
Conversation
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
|
Please rebase this branch |
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used. This PR makes retry delays context-aware and avoids sleeping after the final attempt.
Changes:
- Uses context-aware retry sleeping.
- Adds cancellation and final-attempt timing tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
github/transport.go |
Updates retry-delay behavior. |
github/transport_test.go |
Tests cancellation and final retry timing. |
Suppressed comments (1)
github/transport_test.go:537
- This aliases and mutates the process-wide
http.DefaultClient, leaving the retry transport installed after the test and making later tests depend on execution order. Use a dedicated client for this test.
httpClient := http.DefaultClient
httpClient.Transport = NewRetryTransport(http.DefaultTransport,
WithMaxRetries(1),
WithRetryDelay(10*time.Second),
)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
stevehipwell
left a comment
There was a problem hiding this comment.
@yoshi-taka please could you look at the Copilot review comments.
|
Addressed the Copilot review comments in 280d6c6:
The RetryTransport and related transport tests pass. Could you please take another look? |
There was a problem hiding this comment.
🟡 Changes recommended
Intermediate retry response bodies can leak connections and resources.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
stevehipwell
left a comment
There was a problem hiding this comment.
@yoshi-taka please address the Copilot review comments. If you want a reference for how this should work you can check out the new client implementation of the logic which uses the hashicorp/retriable-http package.
f3d177f to
bb9dd12
Compare
|
I've rebased the branch onto the latest What changed
Tests
Verification
|
bb9dd12 to
6dd7be4
Compare
|
The 4KB limit bounds bytes read, not the time spent draining, so the stalled-body concern is valid. This helper follows the existing |
|
@yoshi-taka there is new PR (#3703) to improve the retry logic in the new client. The drain logic is fine for now, but will no longer be required when we bump to Go 1.27. |
|
@yoshi-taka do you want to rebase this PR and align it with the updated new client logic? |
|
I'll rebase onto the current main and align the legacy transport with internal/httpx/retry.go, including close-only response-body cleanup under Go 1.27. I'll keep the legacy retry policy and configuration unchanged. |
Use context-aware retry delays and check cancellation before each attempt. Do not sleep after the final attempt, and close unsent request bodies when cancellation prevents the initial attempt. Drain and close discarded responses before retrying, with a 4KB bound matching the new client implementation. Preserve the final response body for the caller, and discard responses returned alongside transport errors. Add deterministic virtual-time tests for cancellation and retry delays, plus coverage for request body ownership, exhausted responses, bounded draining, and read errors.
6dd7be4 to
b959011
Compare
stevehipwell
left a comment
There was a problem hiding this comment.
Thanks for updating this @yoshi-taka. Just a couple of minor changes requested.
|
Both comments addressed. Sorry this has taken so long, and thanks for your patience and continued feedback throughout! |
robert-crandall
left a comment
There was a problem hiding this comment.
Thanks for sticking with this and bringing the legacy retry transport in line with #3739! The context-aware cancellation, skipping the trailing sleep, and response-body cleanup all look solid to me. I left two small non-blocking test notes inline.

time.Sleepwith context-awaresleep()inRetryTransport.RoundTripretry < maxRetries)internal/httpxbehavior on Go 1.27This aligns the legacy transport's request and response lifecycle handling with the updated new client implementation from #3739. The legacy retry policy and provider configuration remain unchanged.
Resolves #ISSUE_NUMBER
Before the change?
RetryTransportusedtime.Sleepbetween retry attempts.RetryTransportalso slept after the final retryable attempt, even when no further retry would be made.GetBody.After the change?
RetryTransportnow uses the existing context-awaresleep(ctx, dur)helper.RetryTransportno longer sleeps after the final retryable attempt.GetBodyor the existing buffering fallback.Pull request checklist
Does this introduce a breaking change?