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

when will redis server clean invalid client? #1810

Closed
vanillar7 opened this Issue Jun 12, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@vanillar7

vanillar7 commented Jun 12, 2014

the scene:

  1. using redis-cli connect to redis server that is on another host. this client marked A
  2. send "keys * " command to redis server.
  3. send "client list" command show the clients of redis server. we can see client A.
  4. turn off network of redis server host.
  5. kill client A.
  6. turn on network of redis server host.
  7. start client B, and send "client list" command show the clients of redis server. we can see client A and client B.
    but in the fifth step, we already kill the client A. and in the host of client A, there is no connection of client A (using "netstat -antp" command check). why client A is still in the client list of redis server ? and when will redis server clean invalid client?
@mattsta

This comment has been minimized.

Contributor

mattsta commented Jun 21, 2014

Redis has a configuration option for "max client idle time" and by default, the timeout is unlimited.

Since your client didn't disconnect (you vanished the network entirely), you your dead client will either never go away or only go away after the very long TCP timeout of 2 hours.

In redis.conf:

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

Redis also has an option to enable keepalives so Redis can actively detect invalid clients that didn't disconnect properly:

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 60 seconds.
tcp-keepalive 0

@mattsta mattsta closed this Jun 21, 2014

@junneyang

This comment has been minimized.

junneyang commented May 25, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment