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

Fix client reconnect retry attempts #323

Merged
merged 3 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@
return;
}

if (this._reconnectionTimer) {
return;
}

if (reconnection.retries < 1) {
return this._disconnect(ignore, true); // Clear _reconnection state
}
Expand Down
29 changes: 29 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,35 @@ describe('Client', () => {
await server.stop();
});

it('utilizes every connection retry attempt', async () => {

const team = new Teamwork.Team();
const client = new Nes.Client('http://0');

let errorCount = 0;
client.onError = (err) => {

errorCount++;

if (err.message === 'Socket error') {
// This is the final error message once retry attempts have run-out
team.attend();
}
};

try {
await client.connect({ delay: 1, retries: 5 });
}
catch {}

await team.work;

// Should see name number of errors as allowed retry attempts
expect(errorCount).to.equal(5);

client.disconnect();
});

it('aborts reconnect if disconnect is called in between attempts', async () => {

const server = Hapi.server();
Expand Down