Closed HDegroote closed 1 year ago
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Providing a user-defined preClose
option is the way to go.
Cool, thanks! Yes, I'll create a PR.
Are you fine with the proposed update to the default closing flow, where it no longer has a close
hook but instead closes the ws server during the preClose
?
Prerequisites
🚀 Feature Proposal
The current exit flow is:
I'd propose to change it to something like:
Motivation
I have a usecase where I would like the websocket server to shutdown as follows:
This is not hard to implement in my own preClose handler. I managed to get around not being able to provide my own preClose handler by registering it before registering fastify-websocketServer so it runs earlier, but that's quite hacky, and my current solution causes the close handler to error out on
server.close(done)
, because the ws server is already closed.For context, this is the gist of my preClose hook.
If you're open to this feature, I'm fine with PR'ing whichever variation you deem fit. Or if you want to go a bit further, fastify-websocket could also support this kind of shutdown natively, by adding something like
sShutdownMargin
andonShutdownMessage
optionsExample
or