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 for SIGTERM
- 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 [email protected]
Additional context
The normal process for a Unary RPC (that I can deduce from debugging) is as follows:
Client opens stream to Server
Client sends request to Server
Server sends response to Client
Client closes stream.
When using the tryShutdown method the process is different.
Client opens stream to Server
Client sends request to Server
tryShutdown is called
Server calls close on http2 session
Server sends response to Client
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.
Problem description
When using
tryShutdownto gracefully shutdown a server, it doesn't let unary RPCs finish successfully.Reproduction steps
process.onhandler forSIGTERMSIGTERMto the server process.Environment
Additional context
The normal process for a Unary RPC (that I can deduce from debugging) is as follows:
Clientopens stream toServerClientsends request toServerServersends response toClientClientcloses stream.When using the
tryShutdownmethod the process is different.Clientopens stream toServerClientsends request toServertryShutdownis calledServercallscloseon http2 sessionServersends response toClientClientsee'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()fromtryShutdownfixes the problem for Unary GRPCs, but obviously doesn't for Streaming GRPCs.