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?
3 Answers
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
Comments
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
2 Comments
batazor
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?
Tinwor
@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
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/