2

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 3

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

Link to source code

Sign up to request clarification or add additional context in comments.

Comments

4

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

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 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
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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.