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

Retry middleware ignores the context.CancelFunc returned by context.WithTimeout #203

Open
silverspace opened this issue Apr 1, 2019 · 0 comments · May be fixed by #279
Open

Retry middleware ignores the context.CancelFunc returned by context.WithTimeout #203

silverspace opened this issue Apr 1, 2019 · 0 comments · May be fixed by #279

Comments

@silverspace
Copy link

The go-grpc-middleware retry middleware has a function perCallContext that calls context.WithTimeout and ignores the returned cancel function. According to the context.WithTimeout docs:

// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this Context complete:
//
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
// defer cancel() // releases resources if slowOperation completes before timeout elapses
// return slowOperation(ctx)
// }

Here is the offending code in https://github.com/grpc-ecosystem/go-grpc-middleware/blob/master/retry/retry.go#L290

func perCallContext(parentCtx context.Context, callOpts *options, attempt uint) context.Context {
	ctx := parentCtx
	if callOpts.perCallTimeout != 0 {
		ctx, _ = context.WithTimeout(ctx, callOpts.perCallTimeout)
	}
        ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant