Closed
Description
This server calls s.server.close()
1 second after a client connects.
io = require 'socket.io'
s = io.listen 4321
s.sockets.on 'connection', (socket) ->
setTimeout (-> s.server.close()), 1000
... however, the client is never disconnected:
$ coffee server.coffee
info - socket.io started
debug - client authorized
info - handshake authorized 4096240811453695407
debug - setting request GET /socket.io/1/websocket/4096240811453695407
debug - set heartbeat interval for client 4096240811453695407
debug - client authorized for
debug - websocket writing 1::
new connection
client connected. Server will close in 1 second...
debug - emitting heartbeat for client 4096240811453695407
debug - websocket writing 2::
debug - set heartbeat timeout for client 4096240811453695407
debug - websocket received data packet 2::
debug - got heartbeat packet
debug - cleared heartbeat timeout for client 4096240811453695407
debug - set heartbeat interval for client 4096240811453695407
debug - emitting heartbeat for client 4096240811453695407
debug - websocket writing 2::
debug - set heartbeat timeout for client 4096240811453695407
debug - websocket received data packet 2::
debug - got heartbeat packet
debug - cleared heartbeat timeout for client 4096240811453695407
debug - set heartbeat interval for client 4096240811453695407
debug - emitting heartbeat for client 4096240811453695407
debug - websocket writing 2::
....etc
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
3rd-Eden commentedon Sep 7, 2011
Isn't that Node.js core issue instead of a Socket.IO issue? I would say that Node should clean up all fd's when you want to close the server.
josephg commentedon Sep 7, 2011
Quite possibly, especially considering the server -still doesn't quit even after the client has disconnected- (Actually, it does quit, exactly 15 seconds later). If the listening socket were closed but the client socket wasn't closed, you'd expect closing the client socket to terminate the process at last.
josephg commentedon Sep 7, 2011
I just played with it -
Given this server:
lazy client:
Just like with the socket.io code:
server.close()
causes the server's listening socket to be closed immediatelyWith the native node.js app, the server terminates as soon as the last client connection is closed. With socket.io, the server still closes on its own, but it waits a full 15 seconds after the last client manually disconnects and the process terminates.
I think node.js is probably acting correctly according to its spec. It sort of makes sense to deal with the last http requests properly while a server is shutting down. .. But I don't think the behaviour is the right one in socket.io. (Terminating all the open connections is certainly what I expected to happen when I called
server.close()
).3rd-Eden commentedon Sep 19, 2011
Yes and no, we can just loop over all clients and send a disconnect() packet. So I'm marking this as bug.
setthase commentedon Jun 26, 2013
Does somebody look at this after so long time? Is this on roadmap for one of next release?
jtmalinowski commentedon Jan 10, 2014
dang, I just hit this issue when writing tests
samsonradu commentedon Jan 10, 2014
@JakubMal I'm interested in seeing the test. Could you please post it?
jtmalinowski commentedon Jan 10, 2014
@samsonradu sorry man, my bad! Should have checked twice...