Skip to content

Race condition in delay node - buffer modification during iteration #3

@Dennis-SEG

Description

@Dennis-SEG

Summary

Race condition in 89-delay.js where node.buffer and node.idList are modified in callbacks without proper synchronization.

Location

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

Problem

// Line 161-168: setTimeout callback
setTimeout(function() {
    node.idList.splice(node.idList.indexOf(id),1);  // indexOf could return -1
    ...
}, node.timeout);

// Meanwhile, clearDelayList() at line 126-127 runs:
for (var i=0; i<len; i++ ) { node.idList[i].clear(); }
node.idList = [];  // Clears the list during iteration

Race condition scenario:

  1. setTimeout callback is registered (line 161)
  2. clearDelayList() runs and empties node.idList
  3. setTimeout callback executes, indexOf(id) returns -1
  4. splice(-1, 1) removes the LAST element instead of nothing

Impact

Corrupted delay queue state, potential message loss or duplicate sends.

Lines affected

109-122, 161-175, 180-202, 207-226

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions