Closing the server does not clear polling timers
See original GitHub issueIf a socket is in the process of upgrading when io.close is called, the server won’t exit cleanly until the polling connection pings out.
Here’s a test case:
var http = require('http');
var Server = require('socket.io');
var Client = require('socket.io-client');
var server = http.createServer();
var io = Server(server);
io.on('connection', function (socket) {
console.log('server connection');
socket.on('disconnect', function () {
console.log('server disconnected');
socket.disconnect();
});
});
server.listen(8080, function () {
var socket = Client('http://localhost:8080/');
socket.on('connect', function () {
console.log('client connected');
console.log('closing');
io.close();
});
socket.on('disconnect', function () {
console.log('client disconnected');
socket.close();
});
});
server.on('close', function () {
console.log('shutdown');
});
The server will output “shutdown”, but the process will not exit until the socket times out two minutes later (if debug is setup to show socket.io, you can see the timeout event). If I delay the close 5 seconds to allow the socket to upgrade, then the process exits cleanly.
The only workaround I can come up with is to force process exit in the server close event. Unfortunately, the reason I made this test case was that my main application never fires the close event. I can’t seem to reproduce that in a test case, but I suspect it might be related to this issue.
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Using poll() instead of select() - IBM
The ioctl() API sets the socket to be nonblocking. All of the sockets for the incoming connections are also nonblocking because they inherit...
Read more >Long polling - The Modern JavaScript Tutorial
Long polling is the simplest way of having persistent connection with server, that doesn't use any specific protocol like WebSocket or ...
Read more >Short-polling vs Long-polling for real time web applications?
Just for the sake of argument. Both are http request (xhr), and its at least partially untrue it uses more server resources (depends...
Read more >Socket.Poll Method (System.Net.Sockets) | Microsoft Learn
true if data is available for reading;. -or-. true if the connection has been closed, reset, or terminated;. otherwise, returns false .
Read more >Poll Watchers - Vote.PA.Gov
inspect a numbered list of voters and voting check list, but only when there are no voters in the polling place and under...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
While I’m thankful for the sudden amount of attention this issue is getting, please don’t fill up the comments with +1s. All that does is annoy project maintainers. Explanations of why this bug affects you are much more effective.
We’ve merged a solution for this and it will shortly be in a release.