Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing 'close' behavior on server stop #22

Open
joshkel opened this issue Oct 19, 2022 · 0 comments
Open

Confusing 'close' behavior on server stop #22

joshkel opened this issue Oct 19, 2022 · 0 comments

Comments

@joshkel
Copy link
Contributor

joshkel commented Oct 19, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant