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

issue to connect to elasticache #33

Open
yiwong2001 opened this issue Mar 1, 2019 · 10 comments
Open

issue to connect to elasticache #33

yiwong2001 opened this issue Mar 1, 2019 · 10 comments

Comments

@yiwong2001
Copy link

yiwong2001 commented Mar 1, 2019

Hi,

I am running clustr against an AWS ElastiCache cluster (5.0 version). I have one master node and two slaves. Iam using the cluster configuration endpoint to connect to the cluster.

var client = new RedisClustr({
  servers: [
    {
      host: 'xxxxx.jwkwkt.0001.euw1.cache.amazonaws.com'
    }
  ]
});

It is fine to run write task, but when it run read methods like llen, get, then it hangs there.

client.llen(vkey, function (err, sum) { // it is stopped at this stage
console.log("sum..."+sum);
client.set(key, JSON.stringify(i), 'EX', 60); // it can be run if it is not inside of llen method.
});

I also tried elasticache with cluster enabled to have 3 shards and 3 replica for each. It got same issue to run read method.

Same code works when it is not cluster.

Can you guide me please?

@simontabor
Copy link
Collaborator

Hi @yiwong2001, I'm actively using this with AWS ElastiCache v5 and haven't got the same issue as you.

Could you try logging client.connections and send the result?

@wip0
Copy link

wip0 commented Apr 20, 2019

I tried with configuration endpoint for my cluster (TLS enabled). An error below:
Error: couldn't get client

Here is my code:

const defaultRedisOptions: ClientOpts = {
    retry_strategy: (options: RetryStrategyOptions) => {
        return 50;
    },
    no_ready_check: false,
    enable_offline_queue: true,
};
    const options = {
        servers: {
            host: 'clustercfg.REPLICATION_GROUPID.1swv5v.use1.cache.amazonaws.com',
            port: 6379,
        },
        slotInterval: 1000, // default: none. Interval to repeatedly re-fetch cluster slot configuration
        redisOptions: {
            ...defaultRedisOptions,
            tls: bEncryptInTransit ? {} : null,
        },
        createClient: (port, host) => {
            console.log(`createClient host=${host} port=${port}`);
            return createClient(port, host, {
                ...defaultRedisOptions,
                tls: bEncryptInTransit ? {} : null,
            });
        },
   const redis = new RedisClustr(options);
   redis.on('ready', () => { console.log('REDIS ready'); });
   ...
   promisify(redis.scard).bind(redis)(key); // <--- error here

Here are logs from AWS CloudWatch:

createClient host=clustercfg.REPLICATION_GROUPID.1swv5v.use1.cache.amazonaws.com port=6379
createClient host=REPLICATION_GROUPID-0001-001.REPLICATION_GROUPID.1swv5v.use1.cache.amazonaws.com port=6379
REDIS ready
Error: couldn't get client"

However, if I create redis with node's endpoint directly. It's ok.

    const options = {
        servers: {
            host: 'REPLICATION_GROUPID-0001-001.REPLICATION_GROUPID.1swv5v.use1.cache.amazonaws.com',
            port: 6379,
        },
...

But this does not suite for my case. I need to create it from configuration endpoint.

@wip0
Copy link

wip0 commented Apr 20, 2019

@simontabor Could you give me an example of your codes, please?

@aravindgopall
Copy link

aravindgopall commented Apr 25, 2019

@wip0 @simontabor refer these : gosquared/stash#7 and #37

@simontabor
Copy link
Collaborator

simontabor commented Apr 26, 2019

Hi @wip0 @aravindgopall, you should be able to avoid this issue when connecting to an ElastiCache replication group by waiting for the fullReady event before running commands. fullReady is emitted when redis-clustr has a healthy connection to all the nodes in the cluster, rather than just the configuration endpoint.

@larryboymi
Copy link

If the fullReady event is a requirement, why not add that check to the wrapper?

@aadi99999
Copy link

Has this issue fixed ?
I am making a connection to the cluster via hostname.

@bazingarj
Copy link

I am facing the same Issue. I can see the nodes IP in the logs , but when i get a keys then it says:

Error: couldn't get client
    at /var/task/node_modules/redis-clustr/src/RedisClustr.js:382:23
    at module.exports.RedisClustr.parseArgs (/var/task/node_modules/redis-clustr/src/RedisClustr.js:362:11)
    at /var/task/node_modules/redis-clustr/src/RedisClustr.js:350:12
    at runCbs (/var/task/node_modules/redis-clustr/src/RedisClustr.js:181:7)
    at Command.callback (/var/task/node_modules/redis-clustr/src/RedisClustr.js:265:7)
    at normal_reply (/var/task/node_modules/redis/index.js:726:21)
    at RedisClient.return_reply (/var/task/node_modules/redis/index.js:824:9)
    at JavascriptRedisParser.returnReply (/var/task/node_modules/redis/index.js:192:18)
    at JavascriptRedisParser.execute (/var/task/node_modules/redis/node_modules/redis-parser/lib/parser.js:574:12)
    at Socket.<anonymous> (/var/task/node_modules/redis/index.js:274:27)

@rmitcoder
Copy link

I got this issue as well when upgrading nodejs from v8 to v16. Any idea?

@kaspesla
Copy link

kaspesla commented Feb 3, 2023

I got this and fixed it by doing a short setTimeout to delay before trying to do anything with the cluster.

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

No branches or pull requests

9 participants