ioredis does not detect dead connections
Problem
I am using redis as a cache in a production environment. My redis-server is running on a different VM than my client running ioredis. My problem is that ioredis does not properly handle connections that are "lost" (by which I mean connections that are dead, but have not been properly closed). When this happens, the call-backs of all my .get, .set, etc... calls are only reached after about 11 minutes. For example: [code block] As you can imagine, this is unacceptable behavior for my cache as all the code accessing the cache will get stuck and all requests to my server will timeout. The 'close', 'end' and 'error' events of ioredis are not called, because the tcp connection is not properly closed (no "FIN" tcp packets are sent). This is a common occurrence in a production environment and occurs in the following situations, among others: - the VM running redis-server is shut down - the NAT running between the client and the redis-server (e.g. a firewall or docker's native NATing) eliminates the connection because it has been inactive for some time. This does not happen if you run the client and redis-server on the same machine and just kill (either SIGINT or SIGKILL) the redis-server, as the OS will perform some clean-up and properly close the tcp connections between the redis-server about to be turned off and all connected clients (the ioredis object receives a 'close' event). Coming back to the first situation where the connection is dead because of e.g. a failure of the
Error Output
error if not successful. E.g.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: ioredis does not detect dead connections
Haven't come across this issue before. I'm going to look into it the weekend. Currently you can set the timeout of a request by: [code block] Possibly related issue #61.
Trust Score
3 verifications
- 1
Haven't come across this issue before. I'm going to look into it the weekend. Cu
Haven't come across this issue before. I'm going to look into it the weekend. Currently you can set the timeout of a request by:
Validation
Resolved in redis/ioredis GitHub issue #139. Community reactions: 2 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep