diff --git a/docker/images/n8n/n8n-task-runners.json b/docker/images/n8n/n8n-task-runners.json index 2dd65b67c8..56a48b2d09 100644 --- a/docker/images/n8n/n8n-task-runners.json +++ b/docker/images/n8n/n8n-task-runners.json @@ -9,6 +9,7 @@ "PATH", "N8N_RUNNERS_GRANT_TOKEN", "N8N_RUNNERS_N8N_URI", + "N8N_RUNNERS_MAX_PAYLOAD", "NODE_FUNCTION_ALLOW_BUILTIN", "NODE_FUNCTION_ALLOW_EXTERNAL" ], diff --git a/packages/@n8n/config/src/configs/runners.config.ts b/packages/@n8n/config/src/configs/runners.config.ts index 9c88c77c6a..648959e3f4 100644 --- a/packages/@n8n/config/src/configs/runners.config.ts +++ b/packages/@n8n/config/src/configs/runners.config.ts @@ -32,6 +32,10 @@ export class TaskRunnersConfig { @Env('N8N_RUNNERS_SERVER_LISTEN_ADDRESS') listenAddress: string = '127.0.0.1'; + /** Maximum size of a payload sent to the runner in bytes, Default 1G */ + @Env('N8N_RUNNERS_MAX_PAYLOAD') + maxPayload: number = 1024 * 1024 * 1024; + @Env('N8N_RUNNERS_LAUNCHER_PATH') launcherPath: string = ''; diff --git a/packages/@n8n/config/test/config.test.ts b/packages/@n8n/config/test/config.test.ts index dc85697076..718cb5b73c 100644 --- a/packages/@n8n/config/test/config.test.ts +++ b/packages/@n8n/config/test/config.test.ts @@ -227,6 +227,7 @@ describe('GlobalConfig', () => { path: '/runners', authToken: '', listenAddress: '127.0.0.1', + maxPayload: 1024 * 1024 * 1024, port: 5679, launcherPath: '', launcherRunner: 'javascript', diff --git a/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts b/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts index 9e793a2dc5..d7ec7d85f4 100644 --- a/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts +++ b/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts @@ -169,6 +169,11 @@ export class JsTaskRunner extends TaskRunner { // Missing JS natives btoa, atob, + TextDecoder, + TextDecoderStream, + TextEncoder, + TextEncoderStream, + FormData, }; } diff --git a/packages/@n8n/task-runner/src/task-runner.ts b/packages/@n8n/task-runner/src/task-runner.ts index 952ffcf571..356afb69e5 100644 --- a/packages/@n8n/task-runner/src/task-runner.ts +++ b/packages/@n8n/task-runner/src/task-runner.ts @@ -42,6 +42,8 @@ export interface RPCCallObject { const VALID_TIME_MS = 1000; const VALID_EXTRA_MS = 100; +const DEFAULT_MAX_PAYLOAD_SIZE = 1024 * 1024 * 1024; + export abstract class TaskRunner { id: string = nanoid(); @@ -74,6 +76,9 @@ export abstract class TaskRunner { headers: { authorization: `Bearer ${grantToken}`, }, + maxPayload: process.env.N8N_RUNNERS_MAX_PAYLOAD + ? parseInt(process.env.N8N_RUNNERS_MAX_PAYLOAD) + : DEFAULT_MAX_PAYLOAD_SIZE, }); this.ws.addEventListener('message', this.receiveMessage); this.ws.addEventListener('close', this.stopTaskOffers); diff --git a/packages/cli/src/runners/runner-ws-server.ts b/packages/cli/src/runners/runner-ws-server.ts index 4e19299cee..61538f77a0 100644 --- a/packages/cli/src/runners/runner-ws-server.ts +++ b/packages/cli/src/runners/runner-ws-server.ts @@ -141,7 +141,10 @@ export const setupRunnerServer = (restEndpoint: string, server: Server, app: App } const endpoint = getWsEndpoint(restEndpoint); - const wsServer = new WSServer({ noServer: true }); + const wsServer = new WSServer({ + noServer: true, + maxPayload: globalConfig.taskRunners.maxPayload, + }); server.on('upgrade', (request: TaskRunnerServerInitRequest, socket: Socket, head) => { if (parseUrl(request.url).pathname !== endpoint) { // We can't close the connection here since the Push connections diff --git a/packages/cli/src/runners/task-runner-process.ts b/packages/cli/src/runners/task-runner-process.ts index 1b059bd573..413b74d725 100644 --- a/packages/cli/src/runners/task-runner-process.ts +++ b/packages/cli/src/runners/task-runner-process.ts @@ -72,6 +72,7 @@ export class TaskRunnerProcess { PATH: process.env.PATH, N8N_RUNNERS_GRANT_TOKEN: grantToken, N8N_RUNNERS_N8N_URI: n8nUri, + N8N_RUNNERS_MAX_PAYLOAD: this.runnerConfig.maxPayload.toString(), NODE_FUNCTION_ALLOW_BUILTIN: process.env.NODE_FUNCTION_ALLOW_BUILTIN, NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL, }, @@ -84,6 +85,7 @@ export class TaskRunnerProcess { PATH: process.env.PATH, N8N_RUNNERS_GRANT_TOKEN: grantToken, N8N_RUNNERS_N8N_URI: n8nUri, + N8N_RUNNERS_MAX_PAYLOAD: this.runnerConfig.maxPayload.toString(), NODE_FUNCTION_ALLOW_BUILTIN: process.env.NODE_FUNCTION_ALLOW_BUILTIN, NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL, // For debug logging if enabled diff --git a/packages/cli/src/runners/task-runner-server.ts b/packages/cli/src/runners/task-runner-server.ts index c9d52fc22a..5baaf9fc90 100644 --- a/packages/cli/src/runners/task-runner-server.ts +++ b/packages/cli/src/runners/task-runner-server.ts @@ -114,7 +114,10 @@ export class TaskRunnerServer { a.ok(authToken); a.ok(this.server); - this.wsServer = new WSServer({ noServer: true }); + this.wsServer = new WSServer({ + noServer: true, + maxPayload: this.globalConfig.taskRunners.maxPayload, + }); this.server.on('upgrade', this.handleUpgradeRequest); }