Skip to content

fix: skip retry wait when context deadline is sooner#292

Open
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-skip-backoff-past-deadline
Open

fix: skip retry wait when context deadline is sooner#292
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-skip-backoff-past-deadline

Conversation

@happysnaker

Copy link
Copy Markdown

Summary

When a retryable request has a context deadline that expires before the next backoff wait finishes, the current implementation still sleeps for that full backoff window and only then returns context.DeadlineExceeded from the select on req.Context().Done().

This means callers can spend a long time waiting for a retry that can no longer happen.

This patch checks the computed retry wait against req.Context().Deadline() and returns context.DeadlineExceeded immediately when the next retry window is already impossible.

Closes #272.

What changed

  • compute the retry wait first
  • if timeNow().Add(wait) is later than the request context deadline, abort immediately with context.DeadlineExceeded
  • keep the existing timer/select path unchanged for retry waits that still fit inside the context deadline
  • add focused regression coverage proving the client stops after the first failed attempt instead of waiting for an impossible retry window

Notes

  • no exported API changes
  • this only short-circuits retry waits that are already guaranteed to miss the request deadline
  • existing retry/backoff behavior is unchanged when the next retry still has time to run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backoff wait sleep should check that it wouldn't exceed the context Deadline

1 participant