mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Fixes for race conditions on node closing
This commit is contained in:
parent
b764efdd5a
commit
6d517ceef0
@ -77,7 +77,9 @@ module.exports = function(RED) {
|
|||||||
// Config node state
|
// Config node state
|
||||||
node.connected = false;
|
node.connected = false;
|
||||||
node.connecting = false;
|
node.connecting = false;
|
||||||
|
/** Flag to avoid race conditions between `deregister` and the `close` event of the config node (ex. on redeploy) */
|
||||||
node.closing = false;
|
node.closing = false;
|
||||||
|
/** Options to pass to the stomp-client API */
|
||||||
node.options = {};
|
node.options = {};
|
||||||
node.sessionId = null;
|
node.sessionId = null;
|
||||||
node.subscribtionIndex = 1;
|
node.subscribtionIndex = 1;
|
||||||
@ -232,7 +234,11 @@ module.exports = function(RED) {
|
|||||||
if (!node.client) {
|
if (!node.client) {
|
||||||
node.warn("Can't disconnect, connection not initialized.");
|
node.warn("Can't disconnect, connection not initialized.");
|
||||||
callback();
|
callback();
|
||||||
|
} else if (node.closing) {
|
||||||
|
// Disconnection already in progress
|
||||||
|
callback();
|
||||||
} else {
|
} else {
|
||||||
|
node.closing = true;
|
||||||
node.client.disconnect(function() {
|
node.client.disconnect(function() {
|
||||||
node.log("Disconnected from STOMP server", {sessionId: node.sessionId, url: `${node.options.address}:${node.options.port}`, protocolVersion: node.options.protocolVersion})
|
node.log("Disconnected from STOMP server", {sessionId: node.sessionId, url: `${node.options.address}:${node.options.port}`, protocolVersion: node.options.protocolVersion})
|
||||||
|
|
||||||
@ -317,6 +323,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
|
node.log('Disconnecting...');
|
||||||
node.disconnect(function() { done (); });
|
node.disconnect(function() { done (); });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user