Skip to content

fix: respect context cancellation in RetryTransport - #3383

Open
yoshi-taka wants to merge 2 commits into
integrations:mainfrom
yoshi-taka:fix/retry-transport-ctx-cancellation
Open

fix: respect context cancellation in RetryTransport#3383
yoshi-taka wants to merge 2 commits into
integrations:mainfrom
yoshi-taka:fix/retry-transport-ctx-cancellation

Conversation

@yoshi-taka

Copy link
Copy Markdown
  • Replace time.Sleep with context-aware sleep() in RetryTransport.RoundTrip
  • Skip the delay after the final retry attempt (retry < maxRetries)

RateLimitTransport already uses the existing sleep(ctx, dur) helper (transport.go:122), which respects context cancellation. RetryTransport was using bare time.Sleep, causing it to ignore ctx.Done() during retry delays.

This aligns RetryTransport with the existing pattern in the codebase.

  • Add TestRetryTransport_cancelled: verifies context cancellation interrupts retry delay
  • Add TestRetryTransport_no_sleep_after_last_retry: verifies no delay after final attempt

Resolves #ISSUE_NUMBER


Before the change?

  • RetryTransport used time.Sleep between retry attempts.
  • During retry delays, request context cancellation was not respected.
  • RetryTransport also slept after the final retryable attempt, even when no further retry would be made.

After the change?

  • RetryTransport now uses the existing context-aware sleep(ctx, dur) helper.
  • Retry delays can now be interrupted when the request context is cancelled.
  • RetryTransport no longer sleeps after the final retryable attempt.

Pull request checklist

  • Schema migrations have been created if needed (not needed)
  • 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?

  • Yes
  • No

- Replace `time.Sleep` with context-aware `sleep()` in `RetryTransport.RoundTrip`
- Skip the delay after the final retry attempt (`retry < maxRetries`)

`RateLimitTransport` already uses the existing `sleep(ctx, dur)` helper (transport.go:122), which respects context cancellation. `RetryTransport` was using bare `time.Sleep`, causing it to ignore `ctx.Done()` during retry delays.

This aligns `RetryTransport` with the existing pattern in the codebase.

- Add `TestRetryTransport_cancelled`: verifies context cancellation interrupts retry delay
- Add `TestRetryTransport_no_sleep_after_last_retry`: verifies no delay after final attempt
@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label May 1, 2026
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

👋 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 Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@deiga

deiga commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Please rebase this branch ☺️

@deiga
deiga requested a balanced review from Copilot August 12, 2026 18:28

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

Comment thread github/transport.go

time.Sleep(t.retryDelay)
if retry < t.maxRetries {
sleep(req.Context(), t.retryDelay)
Comment thread github/transport_test.go
Comment on lines +495 to +499
httpClient := http.DefaultClient
httpClient.Transport = NewRetryTransport(http.DefaultTransport,
WithMaxRetries(1),
WithRetryDelay(10*time.Second),
)
@deiga
deiga requested a review from stevehipwell August 13, 2026 12:26

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

LGTM

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

@yoshi-taka please could you look at the Copilot review comments.

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

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants