question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Closing the server does not clear polling timers

See original GitHub issue

If 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:closed
  • Created 8 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Twippedcommented, Jan 21, 2016

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.

0reactions
rauchgcommented, Jan 22, 2016

We’ve merged a solution for this and it will shortly be in a release.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found