From 5d4a37f1e6783ddad80aff69d3f7180961900be8 Mon Sep 17 00:00:00 2001 From: Dennis-SEG Date: Sat, 24 Jan 2026 23:05:51 +0100 Subject: [PATCH] fix: prevent race condition in type-registered event handler Cache activeFlowConfig reference at handler start to prevent issues if activeFlowConfig is reassigned between indexOf and splice operations. Also check that config is still active before calling start() to avoid starting flows for an outdated configuration. Fixes: Dennis-SEG/node-red#6 --- .../node_modules/@node-red/runtime/lib/flows/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/index.js b/packages/node_modules/@node-red/runtime/lib/flows/index.js index f21bd56f9..92b9d1e25 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/index.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/index.js @@ -55,12 +55,14 @@ function init(runtime) { state = 'stop'; if (!typeEventRegistered) { events.on('type-registered',function(type) { - if (activeFlowConfig && activeFlowConfig.missingTypes.length > 0) { - var i = activeFlowConfig.missingTypes.indexOf(type); + var config = activeFlowConfig; + if (config && config.missingTypes.length > 0) { + var i = config.missingTypes.indexOf(type); if (i != -1) { log.info(log._("nodes.flows.registered-missing", {type:type})); - activeFlowConfig.missingTypes.splice(i,1); - if (activeFlowConfig.missingTypes.length === 0 && started) { + config.missingTypes.splice(i,1); + // Only start if config is still the active one + if (config === activeFlowConfig && config.missingTypes.length === 0 && started) { events.emit("runtime-event",{id:"runtime-state",retain: true}); start(); }