Fixes for race conditions on node closing

This commit is contained in:
Olivier Verhaegen 2023-04-17 10:37:10 +02:00 committed by GitHub
parent b764efdd5a
commit 6d517ceef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,7 +77,9 @@ module.exports = function(RED) {
// Config node state
node.connected = 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;
/** Options to pass to the stomp-client API */
node.options = {};
node.sessionId = null;
node.subscribtionIndex = 1;
@ -232,7 +234,11 @@ module.exports = function(RED) {
if (!node.client) {
node.warn("Can't disconnect, connection not initialized.");
callback();
} else if (node.closing) {
// Disconnection already in progress
callback();
} else {
node.closing = true;
node.client.disconnect(function() {
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.log('Disconnecting...');
node.disconnect(function() { done (); });
});
}