Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Client is not reconnecting to hosts that go down and come back up #27

Open
justinhelmer opened this issue Feb 12, 2021 · 1 comment
Open

Comments

@justinhelmer
Copy link

justinhelmer commented Feb 12, 2021

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.

@zensh
Copy link
Member

zensh commented Feb 18, 2021

Hi, you can try to set options:
options.retryMaxDelay = 5 * 1000
options.maxAttempts = 999999

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants