-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Socket closed unexpectedly #2058
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
Comments
Hi, does your redis server seats behind some kind of a proxy/load balancer? Can you please share some more details on your redis/node configuration? |
I tried both ways { And I tried some other way { The save/ get value is working but it throw socket issue a lot in logs Thanks |
Same issue here - it happens in my NodeJS application every 10 minutes, and reconnecting successfully shortly after it. |
@diegothucao @guy-microsoft do you use some kind of a proxy/load balancer? |
no, we do not have it |
What do you mean by "turn socket connect off from redis"? |
because we are facing issue of socket connection closes, could we do not use socket feature from redis, just normally save and get key... Like we have option like that |
@diegothucao Are you saying that you're using a direct connect socket - and that's failing (i.e a unix socket), or that when connecting via a tcp username and host socket things are failing? Can you please bit a bit more explicit? |
connect like above so it opens say socket close unexpected |
I have a multi-server, multi-process application and I'm using redis all over the place. The only instances of redis clients that throw this error are where I'm connecting to the same redis server while using worker threads ie. Connection exists in the main thread and worker thread and the error is constantly thrown every minute. Not an issue when using version 3. |
@a-koka can you please share the code that reproduces the error? |
@leibale here's a stripped-down version of my code. Hope it's reproducible.
redis-client.js
|
This is affecting our application too, very similar client code. |
@a-koka I've just run this code, unfortunately I didn't manage to reproduce the crash (I even tried using "CLIENT LIST SKIPME" from redis-cli, it fires "Redis Error:Error: Socket closed unexpectedly" error on the client, but it does not crash the process, and a new socket is created): const { Worker, isMainThread } = require('worker_threads'),
redis = require('redis');
(async () => {
const client = redis.createClient();
await client.connect();
client.on('error', err => console.error('Redis Error:' + err));
if (isMainThread) {
new Worker(__filename);
client.subscribe('channel1', message => {
console.log('channel1', message);
});
} else {
client.subscribe('channel2', message => {
console.log('channel2', message);
});
}
})(); |
@leibale Would you try publishing data on those two redis channels every 33 ms from another process? If that doesn't help, I am happy to hop on a call, share my screen and capture debugging data. |
@a-koka This didn't do it either :( const { Worker, isMainThread } = require('worker_threads'),
redis = require('redis');
async function client() {
const client = redis.createClient();
client.on('error', err => console.error('Redis Error', err));
await client.connect();
return client;
}
async function run(subscribeTo, publishTo) {
const [subscriber, publisher] = await Promise.all([
client(),
client()
]);
await subscriber.subscribe(subscribeTo, message => {
console.log(subscribeTo, message);
});
setInterval(async () => {
try {
await publisher.publish(publishTo, 'message');
} catch (err) {
console.error('Publish Error', err);
}
}, 10);
}
(async () => {
if (isMainThread) {
new Worker(__filename);
await run('channel1', 'channel2');
} else {
await run('channel2', 'channel1');
}
})(); I'll be on this zoom call for the next 30 minutes, if you can, please join and help me debug it |
@leibale I briefly connected to let you know that I have an upcoming meeting. I can join using the same link in roughly one hour from now at 1:30 PM Pacific. |
@a-koka Sure, take your time :) Edit: apparently zoom closes idle meetings automatically... please ping me when you are ready |
@leibale I'm ready! |
Great chatting with you @leibale and thanks for your help. Below is a summary of the issue and how to fix it. The issue only happens when subscribing to a channel that receives a lot of data. In my case, this was 100 MB every second. When this happens, redis closes the underlying connection with the following error: In node-redis version 3, the connection is closed but no errors are logged. There is an auto-reconnect due to which the issue is never noticed. In node-redis version 4, the connection is closed and errors logged. The fix is as simple as increasing the client-output-buffer-limit on redis. I've set it to unlimited as values up to 512 MB didn't work for me. You might need to increase the maxmemory too, I did not need this. Persist the configuration to file if needed. |
Thanks @leibale |
I checked but not see any new version, it was updated officially ? |
@diegothucao 4.1.0 will be released in a few days |
I too am experiencing this issue, so I am looking forward to 4.1.0 getting released. |
@leibale i have a same problem, i was update node-redis to 4.1.0 `var redis = require("redis"); const redisClient = redis.createClient({ redisClient.on('error', function(err){ (async () => { After 30 minutes when starting nodejs start, redis gives error and reconnects itself SocketClosedUnexpectedlyError: Socket closed unexpectedly |
@leibale , Any update on why the Socket closes unexpectedly ?? |
You should check for client timeout in redis server config => https://redis.io/docs/reference/clients/#client-timeouts |
Not work for me i set the Limit to 5GB still get same error client error SocketClosedUnexpectedlyError: Socket closed unexpectedly any help @leibale ? Downgrading the nodejs redis work fine |
@leibale
My source code is below:
|
I have the same problem, and the only workaround is to downgrade it to 3.1.2... |
downgrading redis? |
+1 |
what about heroku hoppy tier plan since |
Can you change the underlying config file? I'm not too familiar with heroku but the underlying redis configuration needs to be updated which can be done via CLI or config file. |
hi @a-koka thanks a million for your reply. unfortunately i can't do that with hoppy tier, but i my issue is solved once i use redis cloud free plan no it works fine. |
@thanhdkn sorry for the huge delay... if the error is happening every X time, it's probably due to a proxy/load balancer in between redis and your server that does not honor TCP keep alive (such as redis on azure, which will close idle connections after 10m, see here). You can use |
I am not sure that error still happens now. I changed to use Redis on GCP,
do not see the error.
…On Sun, 22 Jan 2023 at 01:21 Leibale Eidelman ***@***.***> wrote:
@thanhdkn <https://github.com/thanhdkn> sorry for the huge delay... if
the error is happening every X time, it's probably due to a proxy/load
balancer in between redis and your server that does not honor TCP keep
alive (such as redis on azure, which will close idle connections after 10m,
see here
<https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-connection#idle-timeout>).
You can use pingInterval to solve it, it'll send PING on interval to make
sure the connection will not be dropped.
—
Reply to this email directly, view it on GitHub
<#2058 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEFAAM2SIJCXZPEZRNJNJY3WTQSL5ANCNFSM5R2I4HJA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Unlike redis on azure, redis on GCP does honor TCP keep alive (as it should), so you actually don't need it :) |
I solved the problem with pingInterval: const redisClient = createClient({ |
@msalvatti that solved for me too, thanks!!! |
Hi mates,
Redis often throw error like above
Socket closed unexpectedly
, could we turn socket connection off from redis?Thanks,
Thu
The text was updated successfully, but these errors were encountered: