redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.07k stars 1.19k forks source link

ioredis client not able to connect in cluster mode with TLS enabled #1800

Open prameet-verma opened 10 months ago

prameet-verma commented 10 months ago

I am running my NextJS application which uses AWS Elasticahe Redis Cluster on server side. Now I am trying use a different redis cluster but in TLS mode with these settings:

image

My code:

import Redis from 'ioredis';
// Use redis adapter if available
try {
  console.log('Starting redis cache in cluster');
  const cluster = new Redis.Cluster( 
    [

      {
        // url: 'rediss://clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379',
        host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
        port: 6379,
        // tls: true,
        // ssl: true
      },
    ],
    {
      //https://github.com/redis/ioredis#special-note-aws-elasticache-clusters-with-tls
      dnsLookup: (address, callback) => callback(null, address),
      lazyConnect: true,
      redisOptions: {
        tls: {
          checkServerIdentity: () => undefined,
        },
        // ssl: true,
      },
    }
  );
  cluster.on('error', (error) => console.log('error listener', error));
  // This will throw if not able to connect on startup
  cluster
    .connect()
    .then(() => {
      console.log('Cluster Connected Successfully');
      cluster.set('prameet', 'localhost');
    })
    .catch((err) => console.error('Catch cluster', err));
  cluster.set('prameet', 'localhost').then(()=> console.log('Cluster value set Successfully'));
} catch (error) {
  console.error('try-catch', error);
}

I have followed the documentation https://github.com/redis/ioredis#special-note-aws-elasticache-clusters-with-tls.

### Error: ClusterAllFailedError: Failed to refresh slots cache. image

Logs with DEBUG mode:

Starting redis cache in cluster
  ioredis:cluster status: [empty] -> wait +0ms
  ioredis:cluster status: wait -> connecting +0ms
  ioredis:cluster resolved hostname clusterurl.mcy1ro.usw2.cache.amazonaws.com to IP clusterurl.mcy1ro.usw2.cache.amazonaws.com +1ms
  ioredis:cluster:connectionPool Reset with [
  ioredis:cluster:connectionPool   {
  ioredis:cluster:connectionPool     host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
  ioredis:cluster:connectionPool     port: 6379
  ioredis:cluster:connectionPool   }
  ioredis:cluster:connectionPool ] +0ms
  ioredis:cluster:connectionPool Connecting to clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 as master +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> wait +0ms
  ioredis:cluster getting slot cache from clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +2ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> wait +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> connecting +1ms
  ioredis:redis queue command[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +0ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +1ms
  ioredis:cluster:subscriber started +1ms
error listener ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:308:31)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:325:21
    at Timeout.<anonymous> (path/node_app/node_modules/ioredis/built/cluster/index.js:662:24)
    at Timeout.run (path/node_app/node_modules/ioredis/built/utils/index.js:117:22)
    at listOnTimeout (node:internal/timers:561:11)
    at processTimers (node:internal/timers:502:7) {
  lastNodeError: Error: timeout
      at timeout (path/node_app/node_modules/ioredis/built/utils/index.js:120:38)
      at EventEmitter.getInfoFromNode (path/node_app/node_modules/ioredis/built/cluster/index.js:659:67)
      at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:314:19)
      at EventEmitter.refreshSlotsCache (path/node_app/node_modules/ioredis/built/cluster/index.js:333:9)
      at path/node_app/node_modules/ioredis/built/cluster/index.js:167:22
}
  ioredis:cluster:connectionPool Reset with [] +1s
  ioredis:cluster:connectionPool Disconnect clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 because the node does not hold any slot +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> close +1s
  ioredis:connection skip reconnecting since the connection is manually closed. +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: close -> end +0ms
  ioredis:cluster:connectionPool Remove clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 from the pool +1ms
  ioredis:cluster:subscriber subscriber has left, selecting a new one... +1s
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +1ms
  ioredis:connection skip reconnecting since the connection is manually closed. +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selecting subscriber failed since there is no node discovered in the cluster yet +1ms
  ioredis:cluster status: connecting -> close +1s
  ioredis:cluster status: close -> reconnecting +0ms
Catch cluster Error: None of startup nodes is available
    at EventEmitter.closeListener (path/node_app/node_modules/ioredis/built/cluster/index.js:159:35)
    at Object.onceWrapper (node:events:627:28)
    at EventEmitter.emit (node:events:525:35)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:578:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
  ioredis:redis status[10.197.235.177:6379 (ioredis-cluster(refresher))]: connecting -> connect +43ms
  ioredis:redis status[10.197.235.177:6379 (ioredis-cluster(refresher))]: connect -> ready +0ms
  ioredis:connection set the connection name [ioredis-cluster(refresher)] +43ms
  ioredis:redis queue command[10.197.235.177:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:connection send 2 commands in offline queue +0ms
  ioredis:redis queue command[10.197.235.177:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +0ms
  ioredis:redis queue command[10.197.235.177:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:cluster Cluster is disconnected. Retrying after 102ms +102ms
  ioredis:cluster status: reconnecting -> connecting +0ms
  ioredis:cluster resolved hostname clusterurl.mcy1ro.usw2.cache.amazonaws.com to IP clusterurl.mcy1ro.usw2.cache.amazonaws.com +0ms
  ioredis:cluster:connectionPool Reset with [
  ioredis:cluster:connectionPool   {
  ioredis:cluster:connectionPool     host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
  ioredis:cluster:connectionPool     port: 6379
  ioredis:cluster:connectionPool   }
  ioredis:cluster:connectionPool ] +103ms
  ioredis:cluster:connectionPool Connecting to clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 as master +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> wait +60ms
  ioredis:cluster:subscriber a new node is discovered and there is no subscriber, selecting a new one... +103ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +0ms
  ioredis:cluster getting slot cache from clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> wait +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> connecting +0ms
  ioredis:redis queue command[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +60ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +0ms
  ioredis:cluster:subscriber started +1ms
  ioredis:redis status[10.197.235.177:6379 (ioredis-cluster(refresher))]: ready -> close +198ms
  ioredis:connection skip reconnecting since the connection is manually closed. +198ms
  ioredis:redis status[10.197.235.177:6379 (ioredis-cluster(refresher))]: close -> end +0ms
  ioredis:redis status[10.197.243.179:6379 (ioredis-cluster(refresher))]: connecting -> connect +743ms
  ioredis:redis status[10.197.243.179:6379 (ioredis-cluster(refresher))]: connect -> ready +1ms
  ioredis:connection set the connection name [ioredis-cluster(refresher)] +744ms
  ioredis:redis write command[10.197.243.179:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:connection send 1 commands in offline queue +1ms
  ioredis:redis write command[10.197.243.179:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +1ms
error listener ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:308:31)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:325:21
    at Timeout.<anonymous> (path/node_app/node_modules/ioredis/built/cluster/index.js:662:24)
    at Timeout.run (path/node_app/node_modules/ioredis/built/utils/index.js:117:22)
    at listOnTimeout (node:internal/timers:561:11)
    at processTimers (node:internal/timers:502:7) {
  lastNodeError: Error: timeout
      at timeout (path/node_app/node_modules/ioredis/built/utils/index.js:120:38)
      at EventEmitter.getInfoFromNode (path/node_app/node_modules/ioredis/built/cluster/index.js:659:67)
      at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:314:19)
      at EventEmitter.refreshSlotsCache (path/node_app/node_modules/ioredis/built/cluster/index.js:333:9)
      at path/node_app/node_modules/ioredis/built/cluster/index.js:167:22
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
  ioredis:cluster:connectionPool Reset with [] +1s
  ioredis:cluster:connectionPool Disconnect clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 because the node does not hold any slot +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> close +58ms
  ioredis:connection skip reconnecting since the connection is manually closed. +58ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: close -> end +0ms
  ioredis:cluster:connectionPool Remove clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 from the pool +0ms
  ioredis:cluster:subscriber subscriber has left, selecting a new one... +1s
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selecting subscriber failed since there is no node discovered in the cluster yet +1ms
  ioredis:cluster status: connecting -> close +1s
  ioredis:cluster status: close -> reconnecting +0ms
  ioredis:cluster Got error Error: None of startup nodes is available
    at EventEmitter.closeListener (path/node_app/node_modules/ioredis/built/cluster/index.js:159:35)
    at Object.onceWrapper (node:events:627:28)
    at EventEmitter.emit (node:events:525:35)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:578:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11) when reconnecting. Ignoring... +0ms
  ioredis:cluster Cluster is disconnected. Retrying after 104ms +105ms
  ioredis:cluster status: reconnecting -> connecting +0ms
  ioredis:cluster resolved hostname clusterurl.mcy1ro.usw2.cache.amazonaws.com to IP clusterurl.mcy1ro.usw2.cache.amazonaws.com +1ms
  ioredis:cluster:connectionPool Reset with [
  ioredis:cluster:connectionPool   {
  ioredis:cluster:connectionPool     host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
  ioredis:cluster:connectionPool     port: 6379
  ioredis:cluster:connectionPool   }
  ioredis:cluster:connectionPool ] +107ms
  ioredis:cluster:connectionPool Connecting to clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 as master +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> wait +108ms
  ioredis:cluster:subscriber a new node is discovered and there is no subscriber, selecting a new one... +108ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +2ms
  ioredis:cluster getting slot cache from clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +3ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> wait +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> connecting +0ms
  ioredis:redis queue command[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +111ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +2ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +0ms
  ioredis:cluster:subscriber started +1ms
  ioredis:redis status[10.197.243.179:6379 (ioredis-cluster(refresher))]: ready -> close +189ms
  ioredis:connection skip reconnecting since the connection is manually closed. +189ms
  ioredis:redis status[10.197.243.179:6379 (ioredis-cluster(refresher))]: close -> end +0ms
  ioredis:redis status[10.197.243.141:6379 (ioredis-cluster(refresher))]: connecting -> connect +725ms
  ioredis:redis status[10.197.243.141:6379 (ioredis-cluster(refresher))]: connect -> ready +0ms
  ioredis:connection set the connection name [ioredis-cluster(refresher)] +725ms
  ioredis:redis write command[10.197.243.141:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:connection send 1 commands in offline queue +1ms
  ioredis:redis write command[10.197.243.141:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +1ms
error listener ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:308:31)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:325:21
    at Timeout.<anonymous> (path/node_app/node_modules/ioredis/built/cluster/index.js:662:24)
    at Timeout.run (path/node_app/node_modules/ioredis/built/utils/index.js:117:22)
    at listOnTimeout (node:internal/timers:561:11)
    at processTimers (node:internal/timers:502:7) {
  lastNodeError: Error: timeout
      at timeout (path/node_app/node_modules/ioredis/built/utils/index.js:120:38)
      at EventEmitter.getInfoFromNode (path/node_app/node_modules/ioredis/built/cluster/index.js:659:67)
      at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:314:19)
      at EventEmitter.refreshSlotsCache (path/node_app/node_modules/ioredis/built/cluster/index.js:333:9)
      at path/node_app/node_modules/ioredis/built/cluster/index.js:167:22
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
  ioredis:cluster:connectionPool Reset with [] +1s
  ioredis:cluster:connectionPool Disconnect clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 because the node does not hold any slot +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> close +88ms
  ioredis:connection skip reconnecting since the connection is manually closed. +88ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: close -> end +0ms
  ioredis:cluster:connectionPool Remove clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 from the pool +2ms
  ioredis:cluster:subscriber subscriber has left, selecting a new one... +1s
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +1ms
  ioredis:cluster:subscriber selecting subscriber failed since there is no node discovered in the cluster yet +1ms
  ioredis:cluster status: connecting -> close +1s
  ioredis:cluster status: close -> reconnecting +0ms
  ioredis:cluster Got error Error: None of startup nodes is available
    at EventEmitter.closeListener (path/node_app/node_modules/ioredis/built/cluster/index.js:159:35)
    at Object.onceWrapper (node:events:627:28)
    at EventEmitter.emit (node:events:525:35)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:578:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11) when reconnecting. Ignoring... +0ms
  ioredis:cluster Cluster is disconnected. Retrying after 106ms +107ms
  ioredis:cluster status: reconnecting -> connecting +0ms
  ioredis:cluster resolved hostname clusterurl.mcy1ro.usw2.cache.amazonaws.com to IP clusterurl.mcy1ro.usw2.cache.amazonaws.com +0ms
  ioredis:cluster:connectionPool Reset with [
  ioredis:cluster:connectionPool   {
  ioredis:cluster:connectionPool     host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
  ioredis:cluster:connectionPool     port: 6379
  ioredis:cluster:connectionPool   }
  ioredis:cluster:connectionPool ] +108ms
  ioredis:cluster:connectionPool Connecting to clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 as master +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> wait +108ms
  ioredis:cluster:subscriber a new node is discovered and there is no subscriber, selecting a new one... +109ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +2ms
  ioredis:cluster getting slot cache from clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +3ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> wait +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> connecting +0ms
  ioredis:redis queue command[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +111ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +0ms
  ioredis:cluster:subscriber started +0ms
  ioredis:redis status[10.197.243.141:6379 (ioredis-cluster(refresher))]: ready -> close +188ms
  ioredis:connection skip reconnecting since the connection is manually closed. +188ms
  ioredis:redis status[10.197.243.141:6379 (ioredis-cluster(refresher))]: close -> end +0ms
  ioredis:redis status[10.197.227.41:6379 (ioredis-cluster(refresher))]: connecting -> connect +723ms
  ioredis:redis status[10.197.227.41:6379 (ioredis-cluster(refresher))]: connect -> ready +0ms
  ioredis:connection set the connection name [ioredis-cluster(refresher)] +723ms
  ioredis:redis write command[10.197.227.41:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:connection send 1 commands in offline queue +1ms
  ioredis:redis write command[10.197.227.41:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +1ms
error listener ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:308:31)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:325:21
    at Timeout.<anonymous> (path/node_app/node_modules/ioredis/built/cluster/index.js:662:24)
    at Timeout.run (path/node_app/node_modules/ioredis/built/utils/index.js:117:22)
    at listOnTimeout (node:internal/timers:561:11)
    at processTimers (node:internal/timers:502:7) {
  lastNodeError: Error: timeout
      at timeout (path/node_app/node_modules/ioredis/built/utils/index.js:120:38)
      at EventEmitter.getInfoFromNode (path/node_app/node_modules/ioredis/built/cluster/index.js:659:67)
      at tryNode (path/node_app/node_modules/ioredis/built/cluster/index.js:314:19)
      at EventEmitter.refreshSlotsCache (path/node_app/node_modules/ioredis/built/cluster/index.js:333:9)
      at path/node_app/node_modules/ioredis/built/cluster/index.js:167:22
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
  ioredis:cluster:connectionPool Reset with [] +1s
  ioredis:cluster:connectionPool Disconnect clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 because the node does not hold any slot +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> close +91ms
  ioredis:connection skip reconnecting since the connection is manually closed. +92ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: close -> end +1ms
  ioredis:cluster:connectionPool Remove clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 from the pool +3ms
  ioredis:cluster:subscriber subscriber has left, selecting a new one... +1s
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +1ms
  ioredis:cluster:subscriber selecting subscriber failed since there is no node discovered in the cluster yet +1ms
  ioredis:cluster status: connecting -> close +1s
  ioredis:cluster status: close -> reconnecting +0ms
  ioredis:cluster Got error Error: None of startup nodes is available
    at EventEmitter.closeListener (path/node_app/node_modules/ioredis/built/cluster/index.js:159:35)
    at Object.onceWrapper (node:events:627:28)
    at EventEmitter.emit (node:events:525:35)
    at path/node_app/node_modules/ioredis/built/cluster/index.js:578:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11) when reconnecting. Ignoring... +0ms
  ioredis:cluster Cluster is disconnected. Retrying after 108ms +109ms
  ioredis:cluster status: reconnecting -> connecting +0ms
  ioredis:cluster resolved hostname clusterurl.mcy1ro.usw2.cache.amazonaws.com to IP clusterurl.mcy1ro.usw2.cache.amazonaws.com +0ms
  ioredis:cluster:connectionPool Reset with [
  ioredis:cluster:connectionPool   {
  ioredis:cluster:connectionPool     host: 'clusterurl.mcy1ro.usw2.cache.amazonaws.com',
  ioredis:cluster:connectionPool     port: 6379
  ioredis:cluster:connectionPool   }
  ioredis:cluster:connectionPool ] +110ms
  ioredis:cluster:connectionPool Connecting to clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 as master +1ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379]: wait -> wait +110ms
  ioredis:cluster:subscriber a new node is discovered and there is no subscriber, selecting a new one... +111ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +2ms
  ioredis:cluster getting slot cache from clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +3ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> wait +0ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: wait -> connecting +0ms
  ioredis:redis queue command[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +2ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> close +0ms
  ioredis:connection skip reconnecting since the connection is manually closed. +114ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: close -> end +0ms
  ioredis:cluster:subscriber selected a subscriber clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 +3ms
  ioredis:redis status[clusterurl.mcy1ro.usw2.cache.amazonaws.com:6379 (ioredis-cluster(subscriber))]: wait -> wait +0ms
  ioredis:cluster:subscriber started +1ms
  ioredis:redis status[10.197.227.41:6379 (ioredis-cluster(refresher))]: ready -> close +182ms
  ioredis:connection skip reconnecting since the connection is manually closed. +182ms
  ioredis:redis status[10.197.227.41:6379 (ioredis-cluster(refresher))]: close -> end +0ms

Please note that I am able to connect to redis cluster via redis-cli and able to perform CRUD operations as well. The same code works with TLS disabled.

rarecrumb commented 10 months ago

What happens when you try lazyConnect: false?

blshukla commented 3 months ago

Hope it helps someone here. We were facing a similar issue and this answer from Stack Overflow worked well for us - https://stackoverflow.com/questions/76409668/how-to-connect-to-amazon-memorydb-for-redis-from-node-running-in-ec2-ecs