Use Fastify hooks to shut down services gracefully
timostamm opened this issue · 0 comments
Is your feature request related to a problem? Please describe.
When setting up a server, it is possible to pass a shutdownSignal:
/**
* To shut down servers gracefully, this option takes an AbortSignal.
* If this signal is aborted, all signals in handler contexts will be aborted
* as well. This gives implementations a chance to wrap up work before the
* server process is killed.
* Abort this signal with a ConnectError to send a message and code to
* clients.
*/
shutdownSignal?: AbortSignal;
This signal will also trigger the signal in the HandlerContext available to all RPC implementations, allowing them to close any open resources.
This is a convenient feature for microservices that might teared down frequently, but the feature is not well integrated into server plugins.
Describe the solution you'd like
Fastify has a close and preClose hooks that @connectrpc/connect-fastify could use to trigger the signal automatically.
Additional context
Usually, services are allowed a grace period to shut down cleanly, but it is unclear how the service could signal back that it is finished.