Skip to content

Conversation

@adomaskizogian
Copy link

@adomaskizogian adomaskizogian commented Sep 25, 2025

Prior to these proposed changes when Do is configured with retry.Context(ctx) context instance that is also used downstream - e.g. on http calls - and then the context is canceled or reached the deadline, config.onRetry callback is invoked immediately followed by termination of retry atempts on the following select block. No actual retry attempt is ever made yet the callback is called.

It is a quite common pattern in codebases that depend on this library when the OnRetry callback is a non-trivial function
:

if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
  return retry.Unrecoverable(err)
}

I propose to terminate early if the returned error is of the same instance the configured context.Err() context.Cause is. If no context is passed on Do setup it will not take into account context cancelation returned by the retryable function. This implementation will honor config.retryIf configured callback if the callback has an exception for context type errors.

@adomaskizogian adomaskizogian changed the title feat: terminate early if context canceled or deadline exceeded feat: terminate early if configured context is canceled or has exceeded deadline Sep 25, 2025
@adomaskizogian
Copy link
Author

@JaSei

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.

1 participant