Skip to content

Commit

Permalink
fix(Email Trigger (IMAP) Node): Ensure connection close does not bloc…
Browse files Browse the repository at this point in the history
…k deactivation (#10689)
  • Loading branch information
ivov authored Sep 6, 2024
1 parent ff73542 commit 156eb72
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 156eb72

Please sign in to comment.