Skip to content
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

Closing the server does not clear polling timers #2069

Closed
Twipped opened this issue Mar 30, 2015 · 11 comments · Fixed by socketio/engine.io#378
Closed

Closing the server does not clear polling timers #2069

Twipped opened this issue Mar 30, 2015 · 11 comments · Fixed by socketio/engine.io#378
Labels
bug Something isn't working

Comments

@Twipped
Copy link

Twipped commented Mar 30, 2015

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.

@rauchg
Copy link
Contributor

rauchg commented Mar 30, 2015

+1

@nkzawa nkzawa added the bug Something isn't working label Apr 19, 2015
@dignifiedquire
Copy link

Any updates on this? This is creating a real problem in karma right now, as the the timers stop the process from exiting cleanly at the end. See karma-runner/karma#1788 for details

@dignifiedquire
Copy link

@oniono please stop, otherwise I'll have to report your account for abuse

@nkzawa
Copy link
Contributor

nkzawa commented Jan 19, 2016

👍 I think it should be fixed asap

@rauchg
Copy link
Contributor

rauchg commented Jan 19, 2016

+1

3 similar comments
@onlywei
Copy link

onlywei commented Jan 20, 2016

+1

@mightyguava
Copy link

+1

@maaravi
Copy link

maaravi commented Jan 21, 2016

+1

@marcusmolchany
Copy link

+1

@Twipped
Copy link
Author

Twipped commented 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.

@rauchg
Copy link
Contributor

rauchg commented Jan 22, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants