From d0cabaf740fe67ac1cba3d77021705e9af3b440c Mon Sep 17 00:00:00 2001 From: Dennis-SEG Date: Sat, 24 Jan 2026 23:00:46 +0100 Subject: [PATCH] fix: prevent race condition in delay node idList splice Check indexOf result before splicing to prevent removing wrong element when clearDelayList() runs between timeout registration and execution. If indexOf returns -1 (id already removed), splice(-1, 1) would incorrectly remove the last element. Now we skip the splice if id is not found. Fixes: Dennis-SEG/node-red#3 --- .../@node-red/nodes/core/function/89-delay.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/89-delay.js b/packages/node_modules/@node-red/nodes/core/function/89-delay.js index c44fa06c5..c4adb1f07 100644 --- a/packages/node_modules/@node-red/nodes/core/function/89-delay.js +++ b/packages/node_modules/@node-red/nodes/core/function/89-delay.js @@ -159,7 +159,8 @@ module.exports = function(RED) { if (node.pauseType === "delay") { node.on("input", function(msg, send, done) { var id = ourTimeout(function() { - node.idList.splice(node.idList.indexOf(id),1); + var idx = node.idList.indexOf(id); + if (idx !== -1) { node.idList.splice(idx, 1); } if (node.timeout > 1000) { node.status({fill:"blue",shape:"dot",text:node.idList.length}); } @@ -184,7 +185,8 @@ module.exports = function(RED) { } if (delayvar < 0) { delayvar = 0; } var id = ourTimeout(function() { - node.idList.splice(node.idList.indexOf(id),1); + var idx = node.idList.indexOf(id); + if (idx !== -1) { node.idList.splice(idx, 1); } if (node.idList.length === 0) { node.status({}); } send(msg); if (delayvar >= 0) { @@ -207,7 +209,8 @@ module.exports = function(RED) { node.on("input", function(msg, send, done) { var wait = node.randomFirst + (node.diff * Math.random()); var id = ourTimeout(function() { - node.idList.splice(node.idList.indexOf(id),1); + var idx = node.idList.indexOf(id); + if (idx !== -1) { node.idList.splice(idx, 1); } send(msg); if (node.timeout >= 1000) { node.status({fill:"blue",shape:"dot",text:node.idList.length});