Closed
Description
Problem description
When using tryShutdown
to gracefully shutdown a server, it doesn't let unary RPCs finish successfully.
Reproduction steps
- Create GRPC server with unary handler that takes some extended amount of time
- Set up a
process.on
handler forSIGTERM
- Call Unary GRPC
- Before it completes send
SIGTERM
to the server process. - Note that client never receives the correct response, just a cancelled call. Even though the server sends the correct data.
Environment
- OS name, version and architecture: OSX 10.15.7
- Node version 17.8.0
- Package name and version grpc-js@1.3.7
Additional context
The normal process for a Unary RPC (that I can deduce from debugging) is as follows:
Client
opens stream toServer
Client
sends request toServer
Server
sends response toClient
Client
closes stream.
When using the tryShutdown
method the process is different.
Client
opens stream toServer
Client
sends request toServer
tryShutdown
is calledServer
callsclose
on http2 sessionServer
sends response toClient
Client
see's that stream has been cancelled, and errors.
The cancellation appears to be coming from the session destruction happening in tryShutdown
. This makes sense for streaming GRPC calls, as they need to be cancelled, but a Unary GRPC should be able to finish its response without the call being cancelled.
Removing the session.close()
from tryShutdown
fixes the problem for Unary GRPCs, but obviously doesn't for Streaming GRPCs.