-
Notifications
You must be signed in to change notification settings - Fork 203
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
Prevented reconnect #165
Comments
I've also needed this use case too.
And also add this line in the close() method:
|
The fix is just to also set |
There is another bug/issue. After |
Good catch! Yes, the early exit from |
This change fixes two issues described here: pladaria#165 1. It's impossible to reconnect after `maxRetries` is exceeded, because the lock is never released 2. It's impossible to reconnect if `close()` was called before the connection has been established This change adds tests and fixes as discussed in the above issue.
This change fixes two issues described here: pladaria#165 1. It's impossible to reconnect after `maxRetries` is exceeded, because the lock is never released 2. It's impossible to reconnect if `close()` was called before the connection has been established This change adds tests and fixes as discussed in the above issue.
This change fixes two issues described here: pladaria#165 1. It's impossible to reconnect after `maxRetries` is exceeded, because the lock is never released 2. It's impossible to reconnect if `close()` was called before the connection has been established This change adds tests and fixes as discussed in the above issue.
I think @ppena-LiveData 's solution is the correct one. If you reset This is a test case that passes if you keep the test('rapidly toggling connection', done => {
const wss = new WebSocketServer({port: PORT});
const ws = new ReconnectingWebSocket(URL, undefined, {
minReconnectionDelay: 100,
maxReconnectionDelay: 200,
});
ws.close();
ws.reconnect();
ws.close();
ws.reconnect();
let connections = 0;
wss.on('connection', () => {
connections++;
});
ws.addEventListener('open', () => {
wss.close(() => {
setTimeout(() => {
expect(connections).toBe(1);
done();
}, 1000);
});
});
}); |
Also, since I've written them if anyone wants tests for the other cases discussed here: test('reconnect after max retries', done => {
const ws = new ReconnectingWebSocket(URL, undefined, {
maxRetries: 1,
maxReconnectionDelay: 200,
});
let closed = false;
ws.addEventListener('error', () => {
if (ws.retryCount === 1 && !closed) {
const wss = new WebSocketServer({port: PORT});
ws.reconnect();
ws.addEventListener('open', () => {
wss.close(() => {
closed = true;
setTimeout(() => {
done();
}, 1000);
});
});
}
});
}); test('reconnect after closing during connection', done => {
const wss = new WebSocketServer({port: PORT});
const ws = new ReconnectingWebSocket(URL, undefined, {
minReconnectionDelay: 100,
maxReconnectionDelay: 200,
});
ws.close();
setTimeout(() => {
ws.reconnect();
ws.addEventListener('open', () => {
wss.close(() => {
setTimeout(() => {
done();
}, 1000);
});
});
}, 1000);
}); |
@alecgibson Great catch! My mistake, use @ppena-LiveData's solutions 🙂 |
Hi All,
This line (if this._connectLock === true) prevents manually invoked reconnect, if the close method was called before the connection has ever been established.
My case: user decides when he wants to stop reconnecting retries, but later he should be able to proceed with reconnecting retries.
Could you please adjust the reconnect method (I hope it's not been used internally and it will not affect other workflows) to be able to call "force" reconnect manually?
Thanks,
Yaroslav
The text was updated successfully, but these errors were encountered: