You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using socket.io-client in Node, if the server is closed too soon after the client connects, disconnect() doesn't work properly and the process never exits.
To reproduce, use this code with Node v5.4.0 and socket.io-client@1.4.3:
(function(){"use strict";varclientIo=require("socket.io-client");varhttp=require("http");vario=require('socket.io');varhttpServer;varserver;varPORT=5020;startServer(function(){console.log("SERVER STARTED");varclient=clientIo("http://localhost:"+PORT);client.on('connect',function(){client.disconnect();stopServer(function(){console.log("COMPLETE! NODE SHOULD EXIT NOW.");});});});functionstartServer(callback){httpServer=http.createServer();server=io(httpServer);httpServer.listen(PORT,callback);};functionstopServer(callback){httpServer.on("close",function(){console.log("SERVER CLOSED");callback();});server.close();};}());
Output:
$ node spikes/socket.io/test.js
SERVER STARTED
SERVER CLOSED
COMPLETE! NODE SHOULD EXIT NOW.
^C
If you introduce a delay in the stopServer() function, everything works fine:
When using socket.io-client in Node, if the server is closed too soon after the client connects, disconnect() doesn't work properly and the process never exits.
To reproduce, use this code with Node v5.4.0 and socket.io-client@1.4.3:
Output:
$ node spikes/socket.io/test.js SERVER STARTED SERVER CLOSED COMPLETE! NODE SHOULD EXIT NOW. ^C
If you introduce a delay in the stopServer() function, everything works fine:
Output:
$ node spikes/socket.io/test.js SERVER STARTED SERVER CLOSED COMPLETE! NODE SHOULD EXIT NOW. $
The text was updated successfully, but these errors were encountered: