From 156eb72ebefa1d963ff46eff6652e2c947ef031b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 6 Sep 2024 12:07:51 +0200 Subject: [PATCH] fix(Email Trigger (IMAP) Node): Ensure connection close does not block deactivation (#10689) --- .../EmailReadImap/v2/EmailReadImapV2.node.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts b/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts index d9268fd5c068a..3af8f9709bd13 100644 --- a/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts +++ b/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts @@ -14,7 +14,7 @@ import type { ITriggerResponse, JsonObject, } from 'n8n-workflow'; -import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; +import { NodeConnectionType, NodeOperationError, TriggerCloseError } from 'n8n-workflow'; import type { ImapSimple, ImapSimpleOptions, Message, MessagePart } from '@n8n/imap'; import { connect as imapConnect, getParts } from '@n8n/imap'; @@ -669,14 +669,19 @@ export class EmailReadImapV2 implements INodeType { } // When workflow and so node gets set to inactive close the connection - async function closeFunction() { + const closeFunction = async () => { closeFunctionWasCalled = true; if (reconnectionInterval) { clearInterval(reconnectionInterval); } - if (connection.closeBox) await connection.closeBox(false); - connection.end(); - } + try { + if (connection.closeBox) await connection.closeBox(false); + connection.end(); + } catch (error) { + // eslint-disable-next-line n8n-nodes-base/node-execute-block-wrong-error-thrown + throw new TriggerCloseError(this.getNode(), { cause: error as Error, level: 'warning' }); + } + }; // Resolve returned-promise so that waiting errors can be emitted returnedPromise.resolve();