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
{{ message }}
Repository navigation
Connect -> Disconnect -> Connect doesn't work #251
Same issue here -- was unable to connect-disconnect-reconnect the way you described.
However, I've found that the following works. Oddly, if you omit the setTimeout and reconnect immediately (or after too short a timeout) then you are immediately disconnected.
socket = io.connect(host);
socket.disconnect();
socket.socket.reconnect(); || socket.socket.connect(host);
works, but since reconnect or second connect disconnect is fired every couple of seconds
None of the above workarounds worked for me. Guys, this is serious show stopper. Why the "Unable to reproduce" tag? My testing env. is latest Chrome on OS X 10.6.
Unfortunately, same problem here. You can not reconnect after disconnection.
Only thing that worked for me after disconnection:
io.j = [];
io.sockets = [];
Edit: it is not only one problem of the client-side disconnect(). It does not clean up data structures on disconnect - you can see that SocketNamespace.$events still has all callbacks for closed connections, etc.
Still facing issues with reconnect.
2nd reconnect causes multiple reconnection events to be fired on the server. (and this multiplies with every subsequent reconnect). Am firing reconnects on a namespace.
spent an afternoon wrestling with unit tests that were timing out because I couldn't connect after disconnecting. {'force new connection':true} resolved the issue. thanks @milani
Same issue here using Cucumber.js. As I have to create and destroy objects, I was having facing the same connect, disconnect, connect failed. Thx @milani and @rawberg
Activity
aarong commentedon Jul 27, 2011
Same issue here -- was unable to connect-disconnect-reconnect the way you described.
However, I've found that the following works. Oddly, if you omit the setTimeout and reconnect immediately (or after too short a timeout) then you are immediately disconnected.
Gorokhov commentedon Aug 18, 2011
socket = io.connect(host);
socket.disconnect();
socket.socket.reconnect(); || socket.socket.connect(host);
works, but since reconnect or second connect disconnect is fired every couple of seconds
milani commentedon Aug 29, 2011
I had the same issue so I could not finish my node knockout entry in time due to this bug :(
Please fix it before any other heart break!
skrat commentedon Sep 21, 2011
None of the above workarounds worked for me. Guys, this is serious show stopper. Why the "Unable to reproduce" tag? My testing env. is latest Chrome on OS X 10.6.
respectTheCode commentedon Oct 3, 2011
I am seeing the same thing. Also calling
io.connect()a second time fails without an error. Has anyone found a workaround?milani commentedon Oct 4, 2011
Use this one:
io.connect(null,{'force new connection':true});skrat commentedon Oct 4, 2011
How convenient, and ugly. What about removing
io.sockets[uuri] = socket;fromio.js:196? What's the point of that punch line?mrjoes commentedon Nov 1, 2011
Unfortunately, same problem here. You can not reconnect after disconnection.
Only thing that worked for me after disconnection:
io.j = [];
io.sockets = [];
Edit: it is not only one problem of the client-side disconnect(). It does not clean up data structures on disconnect - you can see that SocketNamespace.$events still has all callbacks for closed connections, etc.
milani commentedon Nov 1, 2011
@mrjoes Use
io.connect(null,{'force new connection':true});skrat commentedon Nov 1, 2011
All right, is this really the final API for reconnecting? Rather strange.
milani commentedon Nov 1, 2011
@skrat I agree with you. there should be an
io.reconnectAPI.skrat commentedon Nov 1, 2011
I don't think so,
io.connectthenio.disconnectthenio.connectshould just work, as expected.mrjoes commentedon Nov 1, 2011
@milani: and leak memory due to orphaned sockets, event handlers, etc staying in io.sockets[]?
Not very good idea to be honest.
milani commentedon Nov 1, 2011
@mrjoes Are you sure about memory leak? @3rd-Eden from io.socket told me to use this API.
mrjoes commentedon Nov 1, 2011
Nevermind, it won't add socket to io.sockets[] if you pass 'force new connection'.
Though, it is a bit ugly, especially with endpoints, because you're losing multiplexing - it relies on socket in io.sockets to do multiplexing.
4 remaining items
cacois commentedon Nov 28, 2011
@wackfordjf3 Hey thanks, good call. Works now. :)
baradas commentedon Feb 8, 2012
Still facing issues with reconnect.
2nd reconnect causes multiple reconnection events to be fired on the server. (and this multiplies with every subsequent reconnect). Am firing reconnects on a namespace.
socket = io.connect(url{'reconnect':false});socket.disconnect;// 1st disconnect
socket.socket.reconnect();socket.disconnect(); //2nd disconnect
socket.socket.reconnect(); // 2nd reconnect
Am on : socket.io@0.8.7
Further to this :
Ugly way works fine :
delete io.sockets[url];io.j = [];
socket = io.connect(url);
zanhsieh commentedon Mar 19, 2012
Face the same thing as people already have here; even weird in namespace scenario. Drop the solution for namespacing:
var base = 'http://localhost:3000'
, channel = '/chat'
, url = base + channel;
var socket = io.connect(url);
// call socket.disconnect() won't disconnect, so:
io.sockets[base].disconnect();
// reconnect syntax.
delete io.sockets[base]; io.j =[];
socket = io.connect(url);
note: socket.io version - 0.9.0, platform: windows 7 home premium
rawberg commentedon Oct 15, 2012
spent an afternoon wrestling with unit tests that were timing out because I couldn't connect after disconnecting. {'force new connection':true} resolved the issue. thanks @milani
PEM-- commentedon Dec 27, 2012
Same issue here using Cucumber.js. As I have to create and destroy objects, I was having facing the same connect, disconnect, connect failed. Thx @milani and @rawberg
lin04com commentedon Feb 19, 2013
It works for me! Thanks @mrjoes.
Plasma commentedon Jun 25, 2013
Thanks @milani
danjunger commentedon Jun 6, 2014
The 'force new connection' setting is now called 'forceNew' in the v1.0 release for those that might have run into this issue again.
rauchg commentedon Jun 6, 2014
I pushed a commit to add BC with that, so soon no one should have this issue anymore!
pitambar commentedon Jul 17, 2014
it worked 4 me, socket = io.connect(socketUrl,{'forceNew': true });
peteruithoven commentedon Aug 14, 2014
forceNew disables the whole namespace multiplexing system, is that really the solution?
maxcodefranco commentedon Aug 19, 2014
I'm using:
socket= io.connect()
...
// THIS
socket.io.reconnect()
..
rolandhegedus commentedon Mar 14, 2015
nasasutisna commentedon Mar 1, 2019
this solve my problem, thank you mr. milami