How to set a timeout in grpc-gateway?
I want to limit the time the request is executed, where can I set a time limit? Do I need to create an "Interceptor" for this?
Asked
Active
Viewed 2,649 times
2

batazor
- 852
- 2
- 16
- 36
3 Answers
5
Once again I looked through the source code and found the variable in which you can set the default waiting time
runtime.DefaultContextTimeout = 10 * time.Second

batazor
- 852
- 2
- 16
- 36
3
grpc-gateway
support the grpc-timeout through inbound HTTP Grpc-Timeout header. (the last part was copied from the readme.MD).
for more information you should check the document gRPC over HTTP2

Tinwor
- 7,765
- 6
- 35
- 56
-
I mean, defaulted behavior so that it could be set on the server itself. Of course, I can modify the request from the client and insert a header if it does not exist. But are there any other options? – batazor Apr 30 '20 at 10:30
-
@batazor sorry, I didn't understand correctly your question. As you have found there is the DefaultContextTimeout and seems more suitable for your problem. I've voted your answer, I'll keep this one for reference – Tinwor Apr 30 '20 at 10:44
0
I found another way to set a timeout in the "gRPC-gateway" as below. So I hope this will help you.
clientDeadline := time.Now().Add(time.Duration(*deadlineMs) * time.Millisecond)
ctx, cancel := context.WithDeadline(ctx, clientDeadline)
Visite on more details https://grpc.io/blog/deadlines/

0example.com
- 317
- 2
- 4