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

How to set client default timeout #2130

Closed
soyking opened this issue Jun 7, 2018 · 1 comment
Closed

How to set client default timeout #2130

soyking opened this issue Jun 7, 2018 · 1 comment

Comments

@soyking
Copy link

soyking commented Jun 7, 2018

Please answer these questions before submitting your issue.

What version of gRPC are you using?

1.11.0-dev

What version of Go are you using (go version)?

go version go1.10 linux/amd64

What operating system (Linux, Windows, …) and version?

Linux

What did you do?

I tried to add default time out for rpc client to avoid use context.WithTimeout every time.

What did you expect to see?

Find an interface to set default timeout for rpc client.

What did you see instead?

Could not find any way to do that. The only thing could change client context timeout may be MethodConfig, but it seems that it is controlled by server side, right?

Hope to find a way to set client default timeout. Thanks.

@menghanl
Copy link
Contributor

menghanl commented Jun 7, 2018

This can be done using interceptors:
https://godoc.org/google.golang.org/grpc#WithUnaryInterceptor
https://godoc.org/google.golang.org/grpc#WithStreamInterceptor

In the interceptor, call context.WithTimeout to set the timeout, and then make the RPC with the new context.

@menghanl menghanl closed this as completed Jun 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants