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

Reconnect never happens (race conditions) #3358

Closed
ctaschereau opened this issue Oct 26, 2018 · 1 comment
Closed

Reconnect never happens (race conditions) #3358

ctaschereau opened this issue Oct 26, 2018 · 1 comment

Comments

@ctaschereau
Copy link

Current behaviour

A worker does not retry to connect to the socket.io server after a failed attempt if 2 different connections were attempted (into 2 namespaces) at a specific interval.

Steps to reproduce

  1. Have no server to connect to (not really astep ...)
  2. Run this to see the worker close without ever retrying to connect (visible with DEBUG=socket* env variable)
const ioClient = require('socket.io-client');

let nsp1 = ioClient.connect(`http://127.0.0.1:32000/room1`, {reconnect : true});
nsp1.on('connect', () => {
	console.log('nsp1 connected');
});
setTimeout(() => {
	let nsp2 = ioClient.connect(`http://127.0.0.1:32000/room2`, {reconnect : true});
	nsp2.on('connect', () => {
		console.log('nsp2 connected');
	});
}, 1000);

Other information

If we simply remove the timeout, it works. From looking at the code, it appears that the "cleanup" from the 2nd connection attempt actually "cleans up" the timer that is used for the reconnection of the first connection error.

Workaround

This is, of course, an extremely simplified use case. In our real-world application, we had to move around our requires to ensure that both connections were

@sanji-programmer
Copy link

Hi, I'm doing some investigation on open issues involving races (a research project).

I did some investigation using the tool we have developed to exercise different callback interleavings.
I used the test 'should still try to reconnect twice after opening another socket asynchronously' proposed in socketio/socket.io-client#1253

In current socket.io-client version, I could observe by changing the callback interleavings, the test may pass or fail. So, I added the fix proposed by @lolney and the test always passes even with different interleavings. It seems that the fix is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants