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

setPingConnectionInterval for node-redis #1598

Closed
mercury200Hg opened this issue Apr 15, 2021 · 12 comments · Fixed by #2321
Closed

setPingConnectionInterval for node-redis #1598

mercury200Hg opened this issue Apr 15, 2021 · 12 comments · Fixed by #2321
Labels
Evaluating This ticket is still taken into consideration without a clear path forward. feature

Comments

@mercury200Hg
Copy link

mercury200Hg commented Apr 15, 2021

Issue

Basically, if you run redis behind AWS-NLB or Azure-Loadbalancer there's an idle timeout configured by LoadBalancer like 350 seconds for AWS and 4 minutes for azure. Despite the keepalive you set on the machine hosting redis, the connection from the node app will be dropped if it's idle for more than the above time.

Is it possible to enable a parameter like setPingConnectionInterval which basically sends a PING request to redis to keep the connection alive and prevent it from dropping?

This could be same as the setPingConnectionInterval used in Redisson client or setTestOnBorrow in jedis.

If there's existing functionality that takes care of it, please help out in pointing the same. Say- socket_initial_delay which states this will also behave the interval keep-alive message sending to Redis. From what I understand it will keep on sending the messages to keep the connection alive other than the initial delay. Correct me if i am wrong here.


Environment

  • Node.js Version: 9.1.0
  • Redis Version: 5.0.6
  • Platform: Ubuntu-18.04
@mercury200Hg
Copy link
Author

Hi team,
is anyone checking this ?

@mercury200Hg
Copy link
Author

Hi Team,
Can someone guide the process of contributing this feature if it looks good. I mean any policies, processes to take care of when submitting pull requests for the code changes? Or if any docs to be created for review?

@leibale
Copy link
Contributor

leibale commented Jun 25, 2021

Hi @mercury200Hg, we are currently focusing on V4.

Also, I think that this problem should be solved using "TCP keepalive" instead of a PING command.

I'm adding this issue to the V4 to-do list.

@mercury200Hg
Copy link
Author

@leibale TCP keepalive doesn't usually have effect as LoadBalancers don't honour it and closes the connection if idle for more than their fixed time period. This is the case for most of cloud providers.

We tried testing with keepalive but after the designated period given by AWS/Azure loadbalancer the client gives error of - timed out. Now this case has to be handled at client side and connection to be re-initiated and it works after that.

With something which checks PING at certain frequency the connection never remains idle and the errors in app are reduced.

Thanks for adding it in V4 to-do-list. Let me know if i can contribute there.

@leibale
Copy link
Contributor

leibale commented Jun 28, 2021

@mercury200Hg can you please share a link to the load balancer you're using/trying to use? I want to search for another solution, cause sending a PING command just to keep the connection alive is too much in my opinion, there has to be another "less expensive" solution.

Regarding contributing code - feel free to clone the project, checkout to a new branch from the v4 branch, make the changes, and open a PR.

BTW, in the meantime, you can use setInterval or setTimeout to send ping requests every X time:

setInterval(client => {
  client.ping((err) => {
    if (err) console.error('Redis keepalive error', err);
  });
}, X);

@leibale leibale added Evaluating This ticket is still taken into consideration without a clear path forward. feature labels Jun 29, 2021
@mercury200Hg
Copy link
Author

Is this already implemented or there's still scope to add this ? @leibale

@leibale
Copy link
Contributor

leibale commented Aug 10, 2022

I still don't understand why there's a need to issue a PING command in order to keep the TCP connection alive instead of just using the built-in TCP keepalive functionality (https://nodejs.org/api/net.html#socketconnectoptions-connectlistener)

@mercury200Hg
Copy link
Author

That's because for cloud providers like Azure/AWS LoadBalancers don't honor the TCP connection alive set from Redis client.

@leibale
Copy link
Contributor

leibale commented Aug 10, 2022

Why your redis server is behind a load balancer?

@mercury200Hg
Copy link
Author

That's how Azure managed Redis works internally. 😅

leibale added a commit to leibale/node-redis that referenced this issue Nov 2, 2022
@leibale leibale mentioned this issue Nov 10, 2022
leibale added a commit that referenced this issue Nov 10, 2022
* fix #1598 fix #2276 - add `pingInterval` to client config

* setPingTimer on ready (instead of on connect)

* use isReady (instead of isOpen) and fix test

* Update client-configuration.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Evaluating This ticket is still taken into consideration without a clear path forward. feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants