mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(MQTT Node): Close connection if connection attempt fails (#10873)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { connect, type IClientOptions, type MqttClient } from 'mqtt';
|
||||
import { ApplicationError, randomString } from 'n8n-workflow';
|
||||
|
||||
import { formatPrivateKey } from '@utils/utilities';
|
||||
|
||||
interface BaseMqttCredential {
|
||||
@@ -62,6 +63,10 @@ export const createClient = async (credentials: MqttCredential): Promise<MqttCli
|
||||
const onError = (error: Error) => {
|
||||
client.removeListener('connect', onConnect);
|
||||
client.removeListener('error', onError);
|
||||
// mqtt client has an automatic reconnect mechanism that will
|
||||
// keep trying to reconnect until it succeeds unless we
|
||||
// explicitly close the client
|
||||
client.end();
|
||||
reject(new ApplicationError(error.message));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user