mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
ae76ff0aaf
commit
97678577fb
@ -210,7 +210,7 @@ module.exports = function(RED) {
|
||||
startconn(); // start outbound connection
|
||||
}
|
||||
|
||||
node.on("close", function() {
|
||||
node.on("close", function(done) {
|
||||
if (node.heartbeatInterval) {
|
||||
clearInterval(node.heartbeatInterval);
|
||||
}
|
||||
@ -218,19 +218,27 @@ module.exports = function(RED) {
|
||||
delete listenerNodes[node.fullPath];
|
||||
node.server.close();
|
||||
node._inputNodes = [];
|
||||
activeListenerNodes--;
|
||||
// if (activeListenerNodes === 0 && serverUpgradeAdded) {
|
||||
// RED.server.removeListener('upgrade', handleServerUpgrade);
|
||||
// serverUpgradeAdded = false;
|
||||
// }
|
||||
}
|
||||
else {
|
||||
node.closing = true;
|
||||
node.server.close();
|
||||
if (node.tout) {
|
||||
clearTimeout(node.tout);
|
||||
node.tout = null;
|
||||
}
|
||||
//wait 20*50 (1000ms max) for ws to close.
|
||||
//call done when readyState === ws.CLOSED (or 1000ms, whichever comes fist)
|
||||
const closeMonitorInterval = 20;
|
||||
let closeMonitorCount = 50;
|
||||
let si = setInterval(() => {
|
||||
if(node.server.readyState === ws.CLOSED || closeMonitorCount <= 0) {
|
||||
if (node.tout) {
|
||||
clearTimeout(node.tout);
|
||||
node.tout = null;
|
||||
}
|
||||
clearInterval(si);
|
||||
return done();
|
||||
}
|
||||
closeMonitorCount--;
|
||||
if(closeMonitorCount <= 0) {
|
||||
}
|
||||
}, closeMonitorInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user