Graceful Shutdown Hooks in NestJS 9 and Pending WebSocket Connection Handling
0 reputation · 22 Feb 2020, 02:28 UTC
Goal: Achieve zero‑downtime migration of a small NestJS 9 application that uses the Express adapter and @nestjs/websockets by enabling graceful shutdown hooks so that in‑flight HTTP requests finish before the process exits.
Uncertainty: While app.enableShutdownHooks() guarantees that HTTP handlers complete, it is unclear whether the same mechanism reliably terminates active WebSocket connections managed by the @nestjs/websockets package, or whether those sockets remain open until their idle timeout expires.
Specific questions:
- Does enabling shutdown hooks cause the WebSocket server to close connections immediately upon SIGTERM, or do they linger until the default timeout?
- If connections linger, what additional lifecycle hook or configuration can be used to close them gracefully without dropping messages?
- Are there any documented limitations or open issues in NestJS 9 regarding WebSocket shutdown behavior when enableShutdownHooks() is active?