Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticache Redis with cluster mode disabled but failover enabled #2326

Open
cbazureau opened this issue Nov 15, 2022 · 2 comments
Open

Elasticache Redis with cluster mode disabled but failover enabled #2326

cbazureau opened this issue Nov 15, 2022 · 2 comments
Labels

Comments

@cbazureau
Copy link

cbazureau commented Nov 15, 2022

We are facing a READONLY You can't write against a read only replica error (followed by a Socket closed unexpectedly error) when we want to write on our AWS ElastiCache Redis cluster (Cluster mode off) when multi-AZ and failover are enabled.

On redis server side :

configuration

On client (nodejs) side :

2 persistant connexions, one for the "master" (called Primary Endpoint on AWS), one for the "replica" (called Reader Endpoint on AWS)

const ACTIVATE_READ = true;

const writeClient = redis.createClient({ url: '<master-endpoint>', ... });
const readClient = ACTIVATE_READ ? redis.createClient({ url: '<master-endpoint>', ... }) : writeClient;

await writeClient.connect();
if (ACTIVATE_READ) await readClient.connect();

await readClient.get('foo');
await writeClient.set('foo', 'bar', { EX: 30 }); // Fails here if ACTIVATE_READ is true
await readClient.get('foo');
await writeClient.quit();
if (ACTIVATE_READ) await readClient.quit();
  • No issue with the "replica" connexion when multi-AZ and failover are enabled or disabled
  • No issue with the "master" connexion when multi-AZ and failover are disabled or when "master" connexion is used as the only connexion (ACTIVATE_READ = false)
  • When multi-AZ and failover are enable, node-redis seems to go to the wrong client (using the readClient instead of the writeClient).

Questions :

  • Does node-redis support the AWS failover mode, or did i miss something on the configuration ?
  • In case of failover, is there an internal mechanism in node-redis that ensure to switch to the good node.

Environment:

  • Node.js Version: 16 and 18 (at least)
  • Redis Server Version: AWS ElastiCache Redis 6.2.4 with Multi-AZ + failover enable (2 nodes)
  • Node Redis Version: 4.5.0
  • Platform: docker alpine-node
@cbazureau cbazureau added the Bug label Nov 15, 2022
@cbazureau
Copy link
Author

cbazureau commented Nov 16, 2022

FYI i've switched to ioredis with the same configuration (2 connexions, one to write / one to read) and it works

@af-andy
Copy link

af-andy commented Oct 26, 2023

Anybody else run into this and find a solution?

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

No branches or pull requests

2 participants