Skip to content

Commit b207c84

Browse files
committed
fix: adjust socket reconnection delays
1 parent b267125 commit b207c84

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/helper/api-error-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class ErrorHandler {
4949
logger.error('Retrying in 1 minute. Probe temporarily disconnected.');
5050
setTimeout(() => this.socket.connect(), 60 * 1000);
5151
} else {
52-
setTimeout(() => this.socket.connect(), 1000);
52+
setTimeout(() => this.socket.connect(), 2000);
5353
}
5454
};
5555

5656
handleDisconnect = (reason: string): void => {
5757
logger.debug(`Disconnected from API: (${reason}).`);
5858

5959
if (reason === 'io server disconnect') {
60-
this.socket.connect();
60+
setTimeout(() => this.socket.connect(), 2000);
6161
}
6262
};
6363
}

src/probe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ function connect (workerId?: number) {
8686

8787
const socket = io(`${config.get<string>('api.host')}/probes`, {
8888
transports: [ 'websocket' ],
89-
reconnectionDelay: 2000,
89+
reconnectionDelay: 4000,
9090
reconnectionDelayMax: 8000,
91-
randomizationFactor: 0.75,
91+
randomizationFactor: 0.5,
9292
query: {
9393
version: VERSION,
9494
nodeVersion: process.version,

test/unit/probe.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ describe('index module', () => {
114114

115115
expect(ioStub.firstCall.args[1]).to.deep.include({
116116
transports: [ 'websocket' ],
117-
reconnectionDelay: 2000,
117+
reconnectionDelay: 4000,
118118
reconnectionDelayMax: 8000,
119-
randomizationFactor: 0.75,
119+
randomizationFactor: 0.5,
120120
});
121121

122122
expect(ioStub.firstCall.args[1].query.version).to.match(/^\d+.\d+.\d+$/);
@@ -198,6 +198,7 @@ describe('index module', () => {
198198
mockSocket.emit('disconnect');
199199
expect(connectStub.notCalled).to.be.true;
200200
mockSocket.emit('disconnect', 'io server disconnect');
201+
sandbox.clock.tick(2000 + 50);
201202
expect(connectStub.calledOnce).to.be.true;
202203
});
203204

@@ -225,13 +226,13 @@ describe('index module', () => {
225226
expect(connectStub.callCount).to.equal(1);
226227
});
227228

228-
it('should reconnect after 1 second delay on "connect_error" with other messages', async () => {
229+
it('should reconnect after 2 seconds delay on "connect_error" with other messages', async () => {
229230
await import('../../src/probe.js');
230231

231232
mockSocket.emit('connect_error', new Error('some message'));
232233

233234
expect(connectStub.callCount).to.equal(0);
234-
sandbox.clock.tick(1000 + 50);
235+
sandbox.clock.tick(2000 + 50);
235236
expect(connectStub.callCount).to.equal(1);
236237
});
237238

0 commit comments

Comments
 (0)