Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retries with context cancelled will continue to retry without calling user's function #31

Open
csueiras opened this issue Apr 11, 2021 · 0 comments · May be fixed by #32
Open

Retries with context cancelled will continue to retry without calling user's function #31

csueiras opened this issue Apr 11, 2021 · 0 comments · May be fixed by #32

Comments

@csueiras
Copy link

The retry middleware will continue to retry even in the event of the context being cancelled.

r := retry.New(retry.Config{ Times: math.MaxInt32 })
ctx, cancel := context.WithCancel(context.TODO())
cancel() // context is now cancelled
// this will run forever even though the context is cancelled
r.Run(ctx, func(ctx context.Context) error {
  fmt.Println("Running user's function")
  return fmt.Errorf("error")
})

I realize that this might be a design choice, where the command under execution can decide to stop throwing errors if the context is cancelled, but the issue is that once the context is cancelled the command wrapper will no longer call the user's function:

// command is the unit of execution.
type command struct{}

// Run satisfies Runner interface.
func (command) Run(ctx context.Context, f Func) error {
	// Only execute if we reached to the execution and the context has not been cancelled.
	select {
	case <-ctx.Done():
		return errors.ErrContextCanceled
	default:
		return f(ctx)
	}
}

It will just continuously return errors.ErrContextCanceled which is unhandled in any special way in the retry middleware.

@csueiras csueiras linked a pull request Apr 11, 2021 that will close this issue
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 a pull request may close this issue.

1 participant