-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http: server.closeAllConnections does not destroy upgraded (web)sockets #53536
Comments
I find it reasonable and it was like this even before If the method actually needs to close all connections, then I think it would be better to move it to |
cc: @ShogunPanda |
I agree with @lpinca. I do agree we need a similar |
I don't think it should be in Node.js core. It is trivial to do it in userland. const sockets = new Set()
function closeAllConnections() {
for (const socket of sockets) {
socket.destroy();
}
}
server.on('connection', function (socket) {
sockets.add(socket);
socket.on('close', function () {
sockets.delete(socket);
})
}); |
Thanks folks.
Docs PR: #53560 |
Fixed by d7d9278. |
Version
v22.3.0
Platform
Darwin
Subsystem
http
What steps will reproduce the bug?
Running the following script (
node script.js
) reproduces the bug - theclose
callback is never invoked and the process does not terminate until forced to with the second (unreffed) timeout.Output I see:
How often does it reproduce? Is there a required condition?
Reproduces consistently as far as I can tell.
What is the expected behavior? Why is that the expected behavior?
server.closeAllConnections()
is documented:There's no suggestion that a websocket would be an exception to that - I'd expect it to destroy those sockets, the server would be drained, and
'close'
would be emitted.What do you see instead?
The
server.close()
callback is not invoked, the websocket connection stays open.Additional information
If someone can confirm whether this is a bug or docs issue I'd be happy to work on a fix.
Bit of investigation: It looks like these connections don't make it into
ConnectionList
(screenshot), which is whycloseAllConnections
doesn't find them, though they are counted onnet
's_connections
counter (which is used to determine when'close'
is emitted) - maybeon_message_begin
isn't fired fromllhttp
because we're not following usual http request/response? That's as far as I've dug.The text was updated successfully, but these errors were encountered: