Skip to content

Confusing 'close' behavior on server stop #22

@joshkel

Description

@joshkel

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:

/* 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions