Ioredis: ClusterAllFailedError: Failed to refresh slots cache.

Created on 11 Nov 2019  路  15Comments  路  Source: luin/ioredis

Hi All. i have following error can You help me ?
[ioredis] Unhandled error event: ClusterAllFailedError: Failed to refresh slots cache.

code is following.
`"use strict";
require('./config/config');
const Redis = require('ioredis');

(async()=> {

const startupNodes = [
    {host: process.env.REDIS_HOST_1, port: process.env.REDIS_PORT },
    {host: process.env.REDIS_HOST_2, port: process.env.REDIS_PORT}
    ];
const options = {
    slotsRefreshTimeout: 2000,
    dnsLookup: (address, callback) => callback(null, address),
    redisOptions: {
        tls: {},
        password: process.env.REDIS_PASS,
    },
};
const cluster = new Redis.Cluster(startupNodes, options);
console.log(cluster);

})();`

Most helpful comment

Same issue here

All 15 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

Have the same issue. Using an AWS elasticache redis (cluster mode enabled with multiple shards). I get the issue when using in-transit encryption and trying to access behind a NAT instance.

Same issue here

FWIW, I know this issue is re: clustered but I was fighting with this as well (in-transit encryption on, passworded redis) and this connection string finally got me going, I expect it'd work with a cluster as well:

const redis = new Redis({
  host: redisHost,
  port: redisPort,
  password: redisPassword,
  tls: {
    checkServerIdentity: (servername, cert) => {
      // skip certificate hostname validation
      return undefined;
    },
  },
});

Facing the same issue with 4.11.1 ioredis and redis 3.2.2

any updates on this ?

~Same issue here, running latest code:~

ioredis @ 4.16.0
elasticache with engine @ 5.0.6

My particular issue was a result of an improperly deployed security group on the ElastiCache cluster, so it was truly unable to connect.

All seems to work ok with the above library versions!

The following works for me.

Redis version: 5.0.4 on AWS ElasticCache Clustered with TLS and AUTH enabled.
ioredis version: 4.16.0

Code to connect:

const redis = new Redis.Cluster(
            [{ "host": <ELASTI_CACHE_CONFIGURATION_ENDPOINT> }], {
                dnsLookup: (address, callback) => callback(null, address),
                redisOptions: {
                    tls: true,
                    password: <ELASTI_CACHE_REDIS_AUTH>
                }
            });

Make sure you are in the right VPC, Subnet and Security group to connect to ElastiCache along with the correct IAM role

We're having a similar issue.
Redis version: 5.0.4 on AWS ElasticCache Clustered (3 nodes, 1 shard)
ioredis version: 4.16.0

Code to connect:

const Redis = require("ioredis");
var cluster = new Redis.Cluster([
  {
    host: <PRIMARY_RW_ENDPOINT>, port: 6379
  },
  {
   host: <SECONDARY_READERS_ENDPOINT>, port: 6379,
  }
], {
  dnsLookup: (address, callback) => callback(null, address),

  scaleReads: 'slave'
})

This code works, but bypasses the cluster for reads, if I understand it correctly:

const Redis = require("ioredis");
var cluster = new Redis({ host: <PRIMARY_RW_ENDPOINT>, port: 6379 })

I can also connect via redis-cli -h <PRIMARY_RW_ENDPOINT>, so I'm sure VPC, Subnet and Security groups are all correct.

@ion-willo Is your ElastiCache cluster-mode-enabled? If so, I suggest you connect to the single configuration endpoint.

Hi, I have the same issue using AWS ElastiCache & ioredis:

[ElastiCache]
Configuration Endpoint: clustercfg.test1.xxxxxx.use2.cache.amazonaws.com:6379
Engine Version Compatibility: 5.0.6
Parameter Group: default.redis5.0.cluster.on (in-sync)
Engine:Engine: Clustered Redis
Encryption in-transit: Yes
Encryption at-rest: No

[ioredis]
version: 4.17.3

new Cluster([
  {"port":6379,"host":"clustercfg.test1.xxxxxx.use2.cache.amazonaws.com"}
], {
    dnsLookup: (address, callback) => {
            console.log('====[dnsLookup]====');
            return callback(null, address);
    },
    redisOptions: {
            tls: {},
    },
})

Error:
ClusterAllFailedError: Failed to refresh slots cache.

What am I missing ?

I guess you're missing tls.checkServerIdentity and a password, if AUTH is enabled.

I can't vouch for all of the following, but FYI:

return new IORedis.Cluster(endpoints, {
  // https://github.com/luin/ioredis#special-note-aws-elasticache-clusters-with-tls
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore(TS2554) https://github.com/luin/ioredis/pull/1143
  dnsLookup: (address, callback) => callback(null, address),
  redisOptions: {
    connectionName,
    password,
    // https://github.com/luin/ioredis#reconnect-on-error
    reconnectOnError: function(err) {
      // Only reconnect when the error contains "READONLY"
      // `return 2` to resend failed command after reconnecting
      return err.message.includes('READONLY')
    },
    showFriendlyErrorStack: true,
    tls: {
      checkServerIdentity: (/*host, cert*/) => {
        // skip certificate hostname validation
        return undefined
      }
    }
  },
  slotsRefreshTimeout: 3000
})

AUTH is not enabled. My current options (and it's still failing):

{
            slotsRefreshTimeout: 3000,
            dnsLookup: (address, callback) => callback(null, address),
            redisOptions: {
                    showFriendlyErrorStack: true,
                    tls: {
                          checkServerIdentity: (/*host, cert*/) => {
                            // skip certificate hostname validation
                            return undefined
                          }
                    },
            },
}

I suggest setting DEBUG="ioredis:*" and see if anything turns up.
I wonder if it's still trying to do AUTH.

I found my mistake, I'm new into ElastiCache and I didn't realize I need to connect from an EC2 or AWS VPN. I fixed that and it worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eduleboss picture eduleboss  路  3Comments

PhillipWinder picture PhillipWinder  路  3Comments

luckyscript picture luckyscript  路  5Comments

kimmobrunfeldt picture kimmobrunfeldt  路  5Comments

AdriVanHoudt picture AdriVanHoudt  路  4Comments