feat: terminate early if configured context is canceled or has exceeded deadline #139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to these proposed changes when
Dois configured withretry.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.onRetrycallback is invoked immediately followed by termination of retry atempts on the followingselectblock. 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
OnRetrycallback is a non-trivial function:
I propose to terminate early if the returned error is of the same instance the configured
context.Err()context.Causeis. If no context is passed onDosetup it will not take into account context cancelation returned by the retryable function. This implementation will honorconfig.retryIfconfigured callback if the callback has an exception forcontexttype errors.