Skip to content

Commit 81d3243

Browse files
authored
Merge pull request #8 from Dennis-SEG/fix/delay-node-race-condition
fix: prevent race condition in delay node idList splice
2 parents 9c0dd59 + d0cabaf commit 81d3243

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • packages/node_modules/@node-red/nodes/core/function

packages/node_modules/@node-red/nodes/core/function/89-delay.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ module.exports = function(RED) {
159159
if (node.pauseType === "delay") {
160160
node.on("input", function(msg, send, done) {
161161
var id = ourTimeout(function() {
162-
node.idList.splice(node.idList.indexOf(id),1);
162+
var idx = node.idList.indexOf(id);
163+
if (idx !== -1) { node.idList.splice(idx, 1); }
163164
if (node.timeout > 1000) {
164165
node.status({fill:"blue",shape:"dot",text:node.idList.length});
165166
}
@@ -184,7 +185,8 @@ module.exports = function(RED) {
184185
}
185186
if (delayvar < 0) { delayvar = 0; }
186187
var id = ourTimeout(function() {
187-
node.idList.splice(node.idList.indexOf(id),1);
188+
var idx = node.idList.indexOf(id);
189+
if (idx !== -1) { node.idList.splice(idx, 1); }
188190
if (node.idList.length === 0) { node.status({}); }
189191
send(msg);
190192
if (delayvar >= 0) {
@@ -207,7 +209,8 @@ module.exports = function(RED) {
207209
node.on("input", function(msg, send, done) {
208210
var wait = node.randomFirst + (node.diff * Math.random());
209211
var id = ourTimeout(function() {
210-
node.idList.splice(node.idList.indexOf(id),1);
212+
var idx = node.idList.indexOf(id);
213+
if (idx !== -1) { node.idList.splice(idx, 1); }
211214
send(msg);
212215
if (node.timeout >= 1000) {
213216
node.status({fill:"blue",shape:"dot",text:node.idList.length});

0 commit comments

Comments
 (0)