From a6ecb54cc4a215002c22893c6f1ff8da9b0acceb Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 31 Mar 2020 19:25:20 +0100 Subject: [PATCH] Clear node.close timeout to avoid unnecessary work on restart --- .../node_modules/@node-red/runtime/lib/nodes/flows/Flow.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js index 5fa77d505..c132b507b 100644 --- a/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js @@ -571,15 +571,18 @@ function stopNode(node,removed) { Log.trace("Stopping node "+node.type+":"+node.id+(removed?" removed":"")); const start = Date.now(); const closePromise = node.close(removed); + let closeTimer = null; const closeTimeout = new Promise((resolve,reject) => { - setTimeout(() => { + closePromise = setTimeout(() => { reject("Close timed out"); }, nodeCloseTimeout); }); return Promise.race([closePromise,closeTimeout]).then(() => { + clearTimeout(closeTimer); var delta = Date.now() - start; Log.trace("Stopped node "+node.type+":"+node.id+" ("+delta+"ms)" ); }).catch(err => { + clearTimeout(closeTimer); node.error(Log._("nodes.flows.stopping-error",{message:err})); Log.debug(err.stack); })