Trying to create a timeout for grpc connection in the event that the server grpc implementation doesn't specify a callback function, however it seems that no matter what is specified in the options (new Date().getSeconds()+5) the client doesn't terminate the connection
function hello (call, callback) {
console.log(call.request.message)
}
server.addService(client.Hello.service, {hello: hello});
server.bind('localhost:50051', grpc.ServerCredentials.createInsecure());
server.start();
grpcClient = new client.Hello('localhost:50051',
grpc.credentials.createInsecure(),{deadline: new Date().getSeconds()+5}); //
grpcClient.hello({message: "abc"}, function(err, response) {
console.log(response) // doesn't reach here because function hello doesn't callback
})
Java Prime PackgRPC supports assigning timeouts to the requests. It is a way to perform cancellation of requests. It helps to avoid using the resources for both the client and the server for a request whose result would not be useful to the client.
UNAVAILABLE "Connection timed out". Enabling gRPC client keepalives (setting gRPC KEEPALIVE_TIME) will cause the client to set TCP_USER_TIMEOUT to the same value as the gRPC KEEPALIVE_TIMEOUT (default: 20 seconds). The connection will then fail after 20 seconds with the same error: StatusCode.
In Node. js, default server timeout is 0 milliseconds for the latest version and 2min i.e. (120000 milliseconds) for the older version.
Definition and Usage. The server.timeout property sets, or gets, the server's timeout value, in milliseconds. Default is 2 minutes (120000 milliseconds) Set the server. timeout property to 0 to avoid having a default timeout value.
You can also set rpc deadline as:
function getRPCDeadline(rpcType) {
timeAllowed = 5000
switch(rpcType) {
case 1:
timeAllowed = 5000 // LIGHT RPC
break
case 2 :
timeAllowed = 7000 // HEAVY RPC
break
default :
console.log("Invalid RPC Type: Using Default Timeout")
}
return new Date( Date.now() + timeAllowed )
}
And then use this function while calling any rpc:
var deadline = getRPCDeadline(1)
grpcClient.hello({message: "abc"},{deadline: deadline}, function(err, response) {
console.log(err)
console.log(response)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With