batazor
batazor

Reputation: 992

How to set a timeout in grpc-gateway?

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

Answers (3)

0example.com
0example.com

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

batazor
batazor

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

Link to source code

Upvotes: 5

Tinwor
Tinwor

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

Related Questions