From 0d8aada49005d6a6078e8460003a0de61a8f423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 13 Nov 2024 14:18:21 +0100 Subject: [PATCH] feat(core): Make all http requests made with `httpRequestWithAuthentication` abortable (#11704) --- packages/core/src/NodeExecuteFunctions.ts | 9 +++++++++ packages/workflow/src/Interfaces.ts | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index e645309644..b3701c1ca3 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -918,6 +918,10 @@ function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequest axiosRequest.params = n8nRequest.qs; + if (n8nRequest.abortSignal) { + axiosRequest.signal = n8nRequest.abortSignal; + } + if (n8nRequest.baseURL !== undefined) { axiosRequest.baseURL = n8nRequest.baseURL; } @@ -1718,6 +1722,11 @@ export async function httpRequestWithAuthentication( ) { removeEmptyBody(requestOptions); + // Cancel this request on execution cancellation + if ('getExecutionCancelSignal' in this) { + requestOptions.abortSignal = this.getExecutionCancelSignal(); + } + let credentialsDecrypted: ICredentialDataDecryptedObject | undefined; try { const parentTypes = additionalData.credentialsHelper.getParentTypes(credentialsType); diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 271fd0838e..41cee333d1 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { CallbackManager as CallbackManagerLC } from '@langchain/core/callbacks/manager'; -import type { AxiosProxyConfig } from 'axios'; +import type { AxiosProxyConfig, GenericAbortSignal } from 'axios'; import type * as express from 'express'; import type FormData from 'form-data'; import type { PathLike } from 'fs'; @@ -529,6 +529,7 @@ export interface IHttpRequestOptions { }; timeout?: number; json?: boolean; + abortSignal?: GenericAbortSignal; } /**