Skip to content

Commit 1aa93f5

Browse files
committed
feat: increase reconnect waiting time
1 parent f1c1b85 commit 1aa93f5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/client/socket.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,27 @@ module.exports = ({ url, token, filters, config, identifyingMetadata }) => {
2727
},
2828
pathname : `/primus/${token}`,
2929
});
30-
const io = new Socket(url);
30+
31+
// Will exponentially back-off from 0.5 seconds to a maximum of 20 minutes
32+
// Retry for a total period of around 4.5 hours
33+
const io = new Socket(url, {
34+
reconnect: {
35+
factor: 1.5,
36+
retries: 30,
37+
max: 20 * 60 * 1000,
38+
},
39+
});
40+
41+
io.on('reconnect scheduled', (opts) => {
42+
const attemptIn = Math.floor(opts.scheduled / 1000);
43+
logger.warn(`Reconnect retry #${opts.attempt} of ${opts.retries} in about ${attemptIn}s`);
44+
});
45+
46+
io.on('reconnect failed', () => {
47+
io.end();
48+
logger.error('Reconnect failed');
49+
process.exit(1);
50+
});
3151

3252
logger.info({ url }, 'broker client is connecting to broker server');
3353

0 commit comments

Comments
 (0)