Repository navigation
fix: respect context cancellation in RetryTransport - #3383
yoshi-taka wants to merge 1 commit 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.
| httpClient := http.DefaultClient | ||
| httpClient.Transport = NewRetryTransport(http.DefaultTransport, | ||
| WithMaxRetries(1), | ||
| WithRetryDelay(10*time.Second), | ||
| ) |
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
|
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.
bb9dd12 to
6dd7be4
Compare
| if resp == nil || resp.Body == nil { | ||
| return | ||
| } | ||
| _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 4*1024)) |
|
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. |

time.Sleepwith context-awaresleep()inRetryTransport.RoundTripretry < maxRetries)RateLimitTransportalready uses the existingsleep(ctx, dur)helper (transport.go:122), which respects context cancellation.RetryTransportwas using baretime.Sleep, causing it to ignorectx.Done()during retry delays.This aligns
RetryTransportwith the existing pattern in the codebase.TestRetryTransport_cancelled: verifies context cancellation interrupts retry delayTestRetryTransport_no_sleep_after_last_retry: verifies no delay after final attemptResolves #ISSUE_NUMBER
Before the change?
RetryTransportusedtime.Sleepbetween retry attempts.RetryTransportalso slept after the final retryable attempt, even when no further retry would be made.After the change?
RetryTransportnow uses the existing context-awaresleep(ctx, dur)helper.RetryTransportno longer sleeps after the final retryable attempt.Pull request checklist
Does this introduce a breaking change?