-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Socket closed unexpectedly #2276
Comments
Same issue here.. running Azure Redis Cache with TLS results in random "Socket closed unexpectedly" errors every 5-10mins after starting my application (on AKS). This error also occurs when running the app locally on my machine (no proxies/load balancers). |
Try setting I think this library is mis-using Node's |
@schmod, do you mean |
it works fine for me locally, pre-production test found this issue.
|
Switched to ioredis for now.. this library is not suitable for production use until the issue is fixed. |
while 3.* is stable, but no bloom module, for me would like to switch to 3.* and implement bloom by other lib. |
I am also seeing this issue and will not upgrade to v4 until it is resolved. Any word on this?!? |
Hi everyone, sorry for the dealy, I was on vacation.. I wasn't able to reproduce the error with "docker run redis/redis-stack-server", can you please help me reproduce the issue so I'll be able to fix it? |
I'll reiterate my previous comment about if (this.#options.connectTimeout) {
socket.setTimeout(this.#options.connectTimeout, () => socket.destroy(new ConnectionTimeoutError()));
} However, From the Node docs:
I'm not sure if this is the cause of the issues described in this thread, but it's almost certainly a bug. |
@schmod the timeout is reset to 0 after the connect event, see this line |
@schmod for some context, I tried to ping the redis server in my health check endpoint, so that there's no inactivity (the health check endpoint is called every 5s). But the connection still terminates after a few minutes (~5-10mins). PS, I also talked to Microsoft support team for the same but there wasn't any issue with the connection options and setup. |
see #1598 |
@leibale I had already tried the ping approach, but this still doesn't work.. I guess there's some issue with the library because I've migrated to ioredis and it works perfectly fine. No drops whatsoever. |
I've tried to reproduce the issue with "Azure Cache for Redis", but didn't manage to... if one of you can make a call with me and show me the issue that will be very helpful :) edit: |
Might be a duplicate of #1598, see https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-connection#idle-timeout |
We are running into this too:
@leibale I'm not sure if it's related to the same problem, we have all the default client settings (i.e. None are set outside of the URL). What would you recommend for recovery/reconnect? Does it silently stop and this |
@leibale could you please release this bug fix ASAP? we are pending for this feature. |
@richardsun2021 in the meantime you can use this code to do (almost) the exact thing: setInterval(client => {
client.ping((err) => {
if (err) console.error('Redis keepalive error', err);
});
}, 9*1000*60);
// azure is closing the socket after 10m of idle time, pinging every 9m seems like a reasonable choice @josh803316 it should reconnect after this error, do you have a listener to |
@leibale Yes, I do have an error listener which was how (I presume) I saw the error in the logs, but I've upgraded the instance size of the elasticache node and set listeners as follows and haven't seen the crash/issue since the change. My assumption is that the request for the large (almost 1MB) json key/value pair was taking more than the 5 second default timeout (on occasion) and so it would hit the socket timeout but then not recover... just don't know why it wouldn't recover/reconnect as you mentioned: const client = cacheManager.store.getClient();
// Only had this before
client.on('error', (error) => {
this.logger.error(error);
});
////////////////////////////////////////
client.on('connect', () => {
this.logger.error('client is connected');
});
client.on('reconnecting', () => {
this.logger.error('client is reconnecting');
});
client.on('ready', () => {
this.logger.error('client is ready');
}); |
I am facing this exact issue now.. any solution? |
@thorep if the solutions discussed above don't work, just use ioredis. Setting connection timeout to 0 didn't work for me, so I migrated to ioredis and it just works. |
@thorep try to use |
I am using redis with elasticache from AWS |
@emanuellarini You should check the If you want, we can have a quick call.. :) |
@leibale thank u i can confirm: using redis in azure and setting pingInterval to 9 minutes fixes the problem why the azure kills the connection if i m already using some redis operations on the database, shouldnt the 10 minutes cooldown get reseted every redis operation? also whats the difference between pingInterval and keepAlive? |
I got the same issue (Socket Closed Unexpectedly) but only with the remote Redis servers, so I figured out that maybe there is a problem with the TLS. So I tried to use |
Shorter ping interval did the trick:
|
between my app service and redis service, there is an aws NLB-network load balancer.
I have four redis client created, and every 2 minutes will get this error:
"error: Socket closed unexpectedly"
Environment:
The text was updated successfully, but these errors were encountered: