question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Elasticache Redis with TLS and Redis Auth gives ClusterAllFailedError

See original GitHub issue

I’m trying to get ioredis (version 4.9.1) to connect to an Elasticache cluster (default.redis4.0.cluster.on, version 4.0.10, Encryption in transit, Redis Auth, 1 shard, 3 nodes).

This is how I’m trying to connect:

const url = "redis://:<password-redacted>@clustercfg.<url-redacted>.use1.cache.amazonaws.com";
const clusterOptions = { redisOptions: { tls: { } } };
const redis = new Redis.Cluster([url], clusterOptions);

But I’m getting the following error repeatedly:

{ ClusterAllFailedError: Failed to refresh slots cache.
     at tryNode (/usr/src/app/node_modules/ioredis/built/cluster/index.js:326:31)
     at /usr/src/app/node_modules/ioredis/built/cluster/index.js:342:21
     at redis.cluster.utils_1.timeout (/usr/src/app/node_modules/ioredis/built/cluster/index.js:568:24)
     at run (/usr/src/app/node_modules/ioredis/built/utils/index.js:150:22)
     at tryCatcher (/usr/src/app/node_modules/standard-as-callback/lib/utils.js:10:19)
     at /usr/src/app/node_modules/standard-as-callback/index.js:31:35
     at process._tickCallback (internal/process/next_tick.js:68:7)
   lastNodeError:
    Error: Connection is closed.
        at close (/usr/src/app/node_modules/ioredis/built/redis/event_handler.js:102:25)
        at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/event_handler.js:73:20)
        at Object.onceWrapper (events.js:277:13)
        at TLSSocket.emit (events.js:194:15)
        at TLSSocket.EventEmitter.emit (domain.js:441:20)
        at _handle.close (net.js:597:12)
        at TCP.done (_tls_wrap.js:388:7) }

Connecting works fine when using ioredis without the Cluster constructor, so I’m pretty sure the URL and the password are correct. This works but occasionally gives MOVED errors, which I think are expected:

const redis = new Redis(url, { tls: { } });

Any clues to what I’m doing wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
headlessmecommented, Apr 18, 2019

I figured out this issue, it seems that passing the password in the URL to the cluster setup won’t result in that password being used to connect to all the cluster nodes that get listed by querying the clustercfg node. In the end I parsed the password out of the URL myself and passed it into redisOptions manually. Seems like this could perhaps be done by default to avoid this error case?

Ended up with something like which is working so far!

const url = "redis://:<password-redacted>@clustercfg.<url-redacted>.use1.cache.amazonaws.com";
const [, password] = (URL.parse(url).auth||'').split(':');
const clusterOptions = { redisOptions: { password: password, tls: { } } };
const redis = new Redis.Cluster([url], clusterOptions);
0reactions
stale[bot]commented, May 18, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ElastiCache in-transit encryption (TLS) - AWS Documentation
Client authentication—using the Redis AUTH feature, the server can authenticate the clients. In-transit encryption conditions. The following constraints on ...
Read more >
Elasticache Redis with TLS and Redis Auth gives ...
Elasticache Redis with TLS and Redis Auth gives ClusterAllFailedError ... I'm trying to get ioredis (version 4.9.1) to connect to an Elasticache ...
Read more >
luin/ioredis - Gitter
Hi I use ioredis scanstream functionality in my AWS lambda. It seems my lambda never terminates successfully whenever it connects to Redis. I...
Read more >
AWS ElastiCache(Redis) With TLS - Medium
By providing in-transit encryption capability, ElastiCache gives you a tool you can use to help protect your data when it is moving from...
Read more >
How to securely connect to ElastiCache Redis instances?
I have a few AWS Elasticache clusters (redis 5.0.6 w/ cluster mode off). ... -it --rm redis redis-cli --verbose -h ***.cache.amazonaws.com --tls --insecure....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found