fix(Email Trigger (IMAP) Node): Ensure connection close does not block deactivation (#10689)

This commit is contained in:
Iván Ovejero 2024-09-06 12:07:51 +02:00 committed by GitHub
parent ff7354228c
commit 156eb72ebe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,7 @@ import type {
ITriggerResponse, ITriggerResponse,
JsonObject, JsonObject,
} from 'n8n-workflow'; } 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 type { ImapSimple, ImapSimpleOptions, Message, MessagePart } from '@n8n/imap';
import { connect as imapConnect, getParts } 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 // When workflow and so node gets set to inactive close the connection
async function closeFunction() { const closeFunction = async () => {
closeFunctionWasCalled = true; closeFunctionWasCalled = true;
if (reconnectionInterval) { if (reconnectionInterval) {
clearInterval(reconnectionInterval); clearInterval(reconnectionInterval);
} }
try {
if (connection.closeBox) await connection.closeBox(false); if (connection.closeBox) await connection.closeBox(false);
connection.end(); 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 // Resolve returned-promise so that waiting errors can be emitted
returnedPromise.resolve(); returnedPromise.resolve();