0

We have created a GRPC server microservice in nestjs which fetches data from the Database and share the result with the client. but need to add some timeout in the GRPC server so if the request is not completed within that time the need to throw an error to the server and terminate the request is there any way to define timeout in the GRPC server

I read there is no option present in the GRPC server for timeout, which needs to be handled in the GRPC client using the deadline parameter.

can you please help me here, please give some examples of GRPC client and server using nestjs

Suraj Dalvi
  • 988
  • 1
  • 20
  • 34

1 Answers1

0

Have you checked Setting timeouts for grpc functions in node js ?

On the client try provide a deadline as a call option. I.e., for the "hello" RPC:

grpcClient.hello({message: "abc"},{deadline: deadline}, function(err, response) {
    console.log(err)
    console.log(response)
});

deadline here is a Date.

Yuri Golobokov
  • 1,829
  • 12
  • 11
  • Thanks, but what about the server, is there any way to add timeouts in the GRPC server? I saw this option keepaliveTimeoutMs, but what is this? is this the ServerTimeout? and if possible do you have a code example for the deadline, I have tried it but it is not working in my case, as hello is a GRPC function it has only an argument, how we can pass the deadline there as a second argument, do we need to define this proto file. Please help me here. – Suraj Dalvi May 31 '23 at 22:25
  • no, there is no timeout on the server side, but you can create your own timer to cancel request on the server after some time if you want. keepalive is a different thing -- it is a mechanism to check if the connection is still alive. Sorry, I don't have an example. – Yuri Golobokov Jun 01 '23 at 16:44