#Close in-flight WebSockets with --watch
1 messages · Page 1 of 1 (latest)
--watch should be the same as manually ctrl-c and restart, --hot is the fancy one which is more hmr and keeps js context
ok, then how do i listen for the process ending so i can manually close the websocket connections?
hmm, i havent looked into that before, but i'd think by killing process it should kill connections?
i mean i think it does "kill" the connection as in it disposes of it but it doesn't actually send websocket close messages
ah
id imagine a process.on exit should work
but also consider trying out --hot instead as it'll try to just keep it open!
i would, but my server has state that gets reset even with --hot so it'll desync with the client
i want to just close the ws so that the client resets itself with the server
doesn't look like it, or at least it doesn't like me using async since server.stop is async
i've tried exit and beforeExit
it doesn't look like i can even do server.publish() in the handler
ok testing without --watch, beforeExit and exit aren't even triggering, despite them being in the docs https://bun.com/docs/guides/process/os-signals
removing the server makes the events work??
i can keep the server if i do server.unref() but then the process doesn't stay alive
if i try to keep it alive with a promise that never resolves then the events don't trigger either
which maybe they're only supposed to if the event queue is empty? but the SIGINT event doesn't fire either
this seems like a bug
if you're on windows and using bun run start, then i think there is some weird bug where it doesnt properly pass on the exit, but in macos they work for me™ in normal mode
i'm on macos
apparently SIGINT fires but only if i register the listener before the server.
and exit and beforeExit still don't work
hmmm
prob as i dont have any long lasting open connections
seems like weird bugs
and SIGINT doesn't fire on watch restarts
yeah that looks like its just for ctrlc
i cant manage to get node working for those exit events fwiw
hm
nvm node does SIGTERM event for their --watch, and bun's doesnt... can you file an issue on bun's repo for that
and also maybe for websockets to properly close on exits (but maybe it makes it take longer 🤷)
#25721 and #25722
ok if i use --hot then i can keep the websocket connections and publish messages to tell the client to close the connection