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
pull/5457/head
Dennis-SEG 2026-01-24 23:00:46 +01:00
parent 1019d52f78
commit d0cabaf740
1 changed files with 6 additions and 3 deletions

View File

@ -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});