When a Redis node dies without closing its connections, a client with no socket timeout doesn’t find out. It waits until the Linux kernel gives up retransmitting, which takes about 15.5 minutes. That’s what froze the n8n workflow engine at Zaher.AI for almost 17 minutes after an Azure Managed Redis failover. TCP keepalive doesn’t fix it. What fixed it is a small watchdog that sends a PING every 5 seconds and drops the socket if nothing at all comes back for 15. In a replay of the failure, the stock n8n image never recovered in 53 minutes. The patched one recovered in 16 seconds.
What broke
Our n8n runs in queue mode on Azure Container Apps: a main instance that schedules and enqueues, workers that run executions, and a webhook instance. They all talk to Azure Managed Redis.
One afternoon the Redis primary node went away. Azure promoted the replica about a minute later, and the old primary came back as a replica a few minutes after that. From Azure’s side it was a routine failover handled in about a minute. The resource health page said “Available” the whole time, and there was no service health notice.
n8n ran zero executions for almost 17 minutes. The last normal execution started at 15:28:45. The next cron tick at 15:29:44 tried to enqueue its job and hung. Nothing ran again until 15:45:40, when main enqueued all 26 backed-up executions at once.
No customer jobs or webhooks came in during the window, and the 28 delayed scheduled executions all ran afterwards with none lost. But our own monitoring workflows run on that n8n, so they were blind for the whole stall.
How it showed up, and what didn’t
The first alert was a Sev2 “container killed / liveness restart”. Nothing had been killed. The alert matched on a KEDAScalerFailed event: the worker autoscaler couldn’t dial Redis. That was the only signal that pointed at Redis at all.
The n8n health endpoints stayed “ok” throughout. They report the Redis client’s own view of its connection, and the client thought its sockets were fine.
The way to see the failover was per-node Redis metrics. The old primary, which held all 19 client connections, stopped reporting. After the promotion, the connected-client count was 2, both fresh connections on the new primary. Everything else was still attached to a node that no longer answered.
Root cause
n8n 2.2.5 builds its ioredis 5.3.2 clients with no socket timeout, maxRetriesPerRequest: null (retry forever) and the OS default keepalive, which waits 2 hours before its first probe.
The old primary vanished without sending a reset or a FIN. Every socket to it went silent. A command already written to one of those sockets sat there unacknowledged, and the kernel kept retransmitting it on its backoff schedule until tcp_retries2=15 ran out, about 15.5 minutes later. Only then did the socket error, ioredis reconnect to the new primary, and the queue move.
The logs showed it in two waves. Around 15:35, idle-ish sockets on all three apps hit read ETIMEDOUT and reconnected. At 15:45, the sockets that had in-flight writes, including main’s queue socket, hit the kernel’s limit. That second wave is the one that let work flow again.
There was a useful contrast case. Two Redis connection drops eleven days earlier were graceful: Redis closed the sockets, and n8n recovered in one to two seconds. When the peer closes the connection, the client recovers right away. When it goes silent, the client waits on the kernel.
Why the obvious fixes don’t work
There’s no environment variable to set. n8n 2.2.5 has no setting for Redis socket timeout or keepalive. I checked the config and the Redis client service at that tag.
Upgrading and turning on keepalive doesn’t work either. Newer n8n has QUEUE_BULL_REDIS_KEEP_ALIVE, and it doesn’t help because TCP keepalive only probes idle sockets. While a socket has unacknowledged data, the kernel retransmits instead of sending keepalive probes, and main’s enqueue socket had exactly that. The companion setting QUEUE_BULL_REDIS_RECONNECT_ON_FAILOVER reacts to READONLY replies, and a dead node sends no replies. I measured this: n8n 2.41.4 with keepalive on still stalled for 15.7 minutes.
Liveness probes can’t catch it. They ask the Redis client if it’s connected, and it says yes.
The fix
The watchdog hooks into the one function every n8n Redis client goes through. Every 5 seconds it sends a PING. If no bytes at all arrive on that socket for 15 seconds after the probe, it destroys the socket. ioredis then runs its normal close, reconnect and resend path, the same one the kernel timeout would trigger 15 minutes later.
module.exports = function watchRedis(client, logger, { intervalMs = 5000, timeoutMs = 15000 } = {}) {
let lastDataAt = 0;
let probeAt = 0; // when the unanswered probe went out, 0 = none
client.on('connect', () => client.stream.on('data', () => (lastDataAt = Date.now())));
const timer = setInterval(() => {
if (client.status !== 'ready') return void (probeAt = 0);
const now = Date.now();
if (probeAt && lastDataAt < probeAt) {
if (now - probeAt < timeoutMs) return;
probeAt = 0;
logger.warn('Redis watchdog: no bytes from Redis, resetting connection');
client.stream.destroy(new Error('redis watchdog timeout'));
return;
}
probeAt = now;
client.ping().catch(() => {});
}, intervalMs);
timer.unref();
client.once('end', () => clearInterval(timer));
};
The important detail is “any bytes”, not “the PONG came back”. My first version required the PING to be answered within 10 seconds, and it killed a healthy worker in the soak test. The reason is the job queue. With worker concurrency 10, Bull queues ten blocking BRPOPLPUSH commands, five seconds each, on one connection. Redis answers commands on a connection in order, so the PONG can legitimately take 50 seconds. But each of those blocking calls returns within 5 seconds, so a live socket is never silent for 15. The silence threshold has to stay above Bull’s 5-second drain delay for the same reason.
The hook is a one-line sed in our Dockerfile, and the build fails if the anchor line isn’t found exactly once, so an n8n upgrade can’t quietly ship without the watchdog.
How I tested it
Azure Managed Redis has no API to trigger a failover on demand, so I built a local replay: queue mode, main plus a worker at concurrency 10, Postgres, Redis 7 with TLS and a password, and a cron every 10 seconds. The fault is an iptables DROP in both directions on every existing Redis socket, so no reset or FIN reaches either side, plus CLIENT KILL on the server, while new connections still work. That matches a dead primary next to a promoted replica.
| Image | First execution after the fault | Failed or duplicated |
|---|---|---|
| Stock production image | never (328 queued, 0 started at 53 min) | 0 |
| Upstream 2.41.4 with keepalive | 941 s | 0 |
| Patched with the watchdog | 15.8 s | 0 |
The stock image did worse in the replay than in production. The 10-second cron pushed 66 KB into the dead socket, which put it into zero-window probing, and each idle socket only noticed it was dead the next time something wrote to it, so the stalls stacked up. Busier real traffic would have made production’s stall longer. The keepalive run showed the same two waves as production.
Two more runs covered false positives. A 20-minute soak under load with no fault ran 738 executions with 0 failures and 0 watchdog resets. The same fault injected under load with 6 executions mid-flight reset the sockets at 13 to 18 seconds, and the first new execution started at 18.4 seconds, with nothing errored and nothing started twice.
What changed in monitoring
The watchdog fixes the stall, but the bigger gap was that nothing noticed it. Health endpoints were green the whole time. So a scheduled workflow now pings an external heartbeat every 5 minutes, with 5 minutes of grace. If the queue stops running work, the heartbeat goes quiet and that alert fires, whatever the health endpoints think.
One follow-up: each watchdog reset logs a few error lines per connection, so a reset across three connections tripped our “error-level log burst” alert. The alert now excludes the watchdog’s own message.
What to check in your own system
- Find every long-lived connection your service holds to Redis, a database or a broker, and check its socket timeout. “Retry forever” plus “no timeout” means the kernel decides when you recover.
- Don’t count on TCP keepalive for sockets that have in-flight writes. It only probes idle connections.
- A health check that asks the client “are you connected?” can’t catch this. Test the work itself: a heartbeat sent from inside the queue, or a probe that goes through the real path.
- Test a silent failure, not a clean one.
iptables -j DROPon established connections is much closer to a dead cloud node than stopping the Redis container.