From f898672a29753774eeb6e166c28ed6f548533517 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Mon, 30 Aug 2021 12:36:18 -0400 Subject: [PATCH] fix: Fix undefined property warning in executeAutoPipeline (#1425) Seen in an uncaughtException handler. ``` err_type=uncaughtException, exiting cause=TypeError: Cannot read property 'Symbol(callbacks)' of undefined at Immediate.executeAutoPipeline (.../node_modules/ioredis/built/autoPipelining.js:34:31) at Shim.applySegment (.../node_modules/newrelic/lib/shim/shim.js:1430:20) at Immediate.wrapper (.../node_modules/newrelic/lib/shim/shim.js:2097:17) at processImmediate (internal/timers.js:463:21) ``` A similar error was among the errors reported in https://github.com/luin/ioredis/issues/1248 I suspect the process.exec might call the callback synchronously in the same tick in some cases, immediately deleting the autopipeline from running pipelines? --- lib/autoPipelining.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/autoPipelining.ts b/lib/autoPipelining.ts index 45df0fe2..9aec27f5 100644 --- a/lib/autoPipelining.ts +++ b/lib/autoPipelining.ts @@ -27,6 +27,16 @@ function executeAutoPipeline(client, slotKey: string) { if (client._runningAutoPipelines.has(slotKey)) { return; } + if (!client._autoPipelines.has(slotKey)) { + /* + Rare edge case. Somehow, something has deleted this running autopipeline in an immediate + call to executeAutoPipeline. + + Maybe the callback in the pipeline.exec is sometimes called in the same tick, + e.g. if redis is disconnected? + */ + return; + } client._runningAutoPipelines.add(slotKey);