Client is not reconnecting to hosts that go down and come back up
justinhelmer opened this issue · 1 comments
We are using thunk-redis
because it is the only node client that we found that accepts multiple hosts (i.e. primary/replica), without Sentinel or Clustering. We are using AWS Elasticache.
When one host goes down, the client correctly responds with data from the other host. However, when the host goes back up, the client does not reconnect to the first host or start serving from the primary.
To replicate, launch redis on two hosts (in my case, launching locally on two separate ports), then run the following:
const redis = require('thunk-redis');
client = redis.createClient(['127.0.0.1:6379', '127.0.0.1:6380'], { clusterMode: false, usePromise: true });
client.set('key', 'value').then(getKeyEverySecond);
function getKeyEverySecond() {
const int = setInterval(async () => {
try {
console.log(await client.get('key'));
} catch (err) {
clearInterval(int);
throw err;
}
}, 1000);
}
Kill one server. You will see the client correctly starts reading from the other server (regardless of which you kill). Then restart the server, immediately. Once running, kill the other server.
You will see:
Error: The redis client was ended
My expectation is that as soon as the first (primary) host goes back up, the client will internally have reconnected to it, and will start serving from it again.
Hi, you can try to set options:
options.retryMaxDelay = 5 * 1000
options.maxAttempts = 999999