-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I wanted to see if I could set up Hapi to cleanly shut down all WebSocket connections when the server shuts down. hapi-plugin-websocket's behavior is confusing here; the source code comments make it sound like it intends to trigger a 'close' event on each connection:
hapi-plugin-websocket/hapi-plugin-websocket.js
Lines 353 to 364 in 84a11a6
| /* close WebSocket server instance */ | |
| if (wss !== null) { | |
| /* trigger the WebSocket server to close everything */ | |
| wss.close(() => { | |
| /* give WebSocket server's callback a chance to execute | |
| (this indirectly calls our "close" subscription above) */ | |
| setTimeout(() => { | |
| /* continue processing inside HAPI */ | |
| wss = null | |
| resolve() | |
| }, 0) | |
| }) |
However, the WebSocketServer.close method doesn't close existing connections. And, since client tracking is enabled, it doesn't even know what existing connections are there.
(To fully implement clean shutdowns, I believe I would need the ability to return a promise from the disconnect callback, so that it can asynchronously update the connection status in an external service - but that's a separate issue.)