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

Concerns about reconnection strategy #414

Closed
matteocontrini opened this issue Dec 18, 2016 · 0 comments
Closed

Concerns about reconnection strategy #414

matteocontrini opened this issue Dec 18, 2016 · 0 comments

Comments

@matteocontrini
Copy link

If you run this code with no Redis instances listening on localhost

const Redis = require('ioredis');

const redis = new Redis('redis://localhost');

redis.on('reconnecting', (t) => {
	console.log(t);
});

The output wil be

λ node test.js
[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
2
[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
4
[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
6
[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
8

What I read from the docs about the reconnecting event is:

The argument of the event is the time (in ms) before reconnecting.

So what I conclude is that with the default retryStrategy, the module will wait 2, 4, 6, 8, 10, ... milliseconds after a connection error before trying to connect again.

Is that value really meant to be milliseconds? After 50 attempts, the module will be waiting only 100 milliseconds before trying to connect again. Isn't this default strategy risking to "flood" the server of requests?

@matteocontrini matteocontrini changed the title Reconnection: seconds or milliseconds? Concerns about reconnection strategy Dec 18, 2016
@luin luin closed this as completed in c5fefb7 Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants