FG
🗄️ Databases

ioredis does not detect dead connections

Freshover 10 years ago
Mar 14, 20260 views
Confidence Score86%
86%

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

Canonical Fix
High Confidence Fix
84% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: ioredis does not detect dead connections

Low Risk

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.

84

Trust Score

3 verifications

100% success
  1. 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

Worked: 3
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

redisiorediscache