Reputation: 992
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?
Upvotes: 2
Views: 3823
Reputation: 307
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/
Upvotes: 0
Reputation: 992
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
Upvotes: 5
Reputation: 7973
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
Upvotes: 4