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

ETIMEDOUT when nodejs is idle for awhile(even if set socket_keepalive = true) #1390

Closed
fanbinghuadev opened this issue Nov 15, 2018 · 11 comments

Comments

@fanbinghuadev
Copy link

Node.js version = v8.12.0
node_redis version = up to date

issue:
in node v8.12.0,i'm getting this error after the nodejs has had no need for redis for a couple hours.But,in node v8.11.1,i don't found issues such so.Is it seem nodejs issue?

@amanshu-kataria
Copy link

I'm also getting the same issue.

@fanbinghuadev
Copy link
Author

I have found the reason. when "socket.setKeepAlive([enable][, initialDelay])" called, "initialDelay" is not set.Set initialDelay (in milliseconds) to set the delay between the last data packet received and the first keepalive probe. Setting 0 for initialDelay will leave the value unchanged from the default (or previous) setting.

@fanbinghuadev
Copy link
Author

Essentially,it is affected by "tcp_keepalive_time" set.

@orhankutlu
Copy link

Any updates on this issue? We are also getting the same issue

@stockholmux
Copy link
Contributor

@orhankutlu @fanbinghuadev and @amanshu-kataria Can you give me some info on your setup? Running Redis locally? Version, etc?

I can't seem to recreate. Would be easy enough to setup an option but I'm trying to determine if it should be default.

@fanbinghuadev
Copy link
Author

I added "client.stream.setKeepAlive(true, 60000);" can solve this issue. @orhankutlu @stockholmux

@stockholmux
Copy link
Contributor

@fanbinghuadev That should work, but it's a band-aid solution and you'll need to do this everytime you re-connect.

I'd like to get to the root of the problem - I can't personally recreate this - if you would please let me know how you're running Redis, I can fix the problem at a higher level.

@fanbinghuadev
Copy link
Author

@stockholmux The root of the problem is that redis server which connected by my redis client will disconnect connection when network is idle for a hour.The machine running redis client has a tcp keepalive timeout set ,when it great than a hour,the issue maked out.So I set tcp keepalive timeout that less than a hour using nodejs api.This can make network is keepalive in a hour .Just So.

@stockholmux
Copy link
Contributor

#1396 should fix allow for this fix. You can specify a initalDelay for the client.

I've taken a look at the node.js net source between 8.11 and 8.12 and I see no real difference between the two as it comes to the keepAlive mechanism. Additionally, there is no rational/universal default here, so it's up to you.

I suspect that the root cause is not 8.11 or 8.12 but some vendor or infrastructure provider brutally closing connections, but the initial delay should work around this issue.

@Fundebug
Copy link

Fundebug commented May 9, 2019

@fanbinghuadev I solved the problem by using your method:

client.on('connect', function () {
    var socket = client.stream
    socket.setKeepAlive(true, 30 * 1000)
})

However, I found that idle redis connection will be disconnected every 2 hours, which is not 1 hour. But I'm not sure about the reason behind it.

@k1r0s
Copy link

k1r0s commented Oct 16, 2023

After connecting, client.stream is undefined. Whats the problem?

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

6 participants