fix: Add config for max task runners payload size (no-changelog) (#11366)

This commit is contained in:
Val 2024-10-23 11:53:21 +01:00 committed by GitHub
parent 3ec103f8ba
commit 5390061f49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 26 additions and 2 deletions

View file

@ -9,6 +9,7 @@
"PATH", "PATH",
"N8N_RUNNERS_GRANT_TOKEN", "N8N_RUNNERS_GRANT_TOKEN",
"N8N_RUNNERS_N8N_URI", "N8N_RUNNERS_N8N_URI",
"N8N_RUNNERS_MAX_PAYLOAD",
"NODE_FUNCTION_ALLOW_BUILTIN", "NODE_FUNCTION_ALLOW_BUILTIN",
"NODE_FUNCTION_ALLOW_EXTERNAL" "NODE_FUNCTION_ALLOW_EXTERNAL"
], ],

View file

@ -32,6 +32,10 @@ export class TaskRunnersConfig {
@Env('N8N_RUNNERS_SERVER_LISTEN_ADDRESS') @Env('N8N_RUNNERS_SERVER_LISTEN_ADDRESS')
listenAddress: string = '127.0.0.1'; 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') @Env('N8N_RUNNERS_LAUNCHER_PATH')
launcherPath: string = ''; launcherPath: string = '';

View file

@ -227,6 +227,7 @@ describe('GlobalConfig', () => {
path: '/runners', path: '/runners',
authToken: '', authToken: '',
listenAddress: '127.0.0.1', listenAddress: '127.0.0.1',
maxPayload: 1024 * 1024 * 1024,
port: 5679, port: 5679,
launcherPath: '', launcherPath: '',
launcherRunner: 'javascript', launcherRunner: 'javascript',

View file

@ -169,6 +169,11 @@ export class JsTaskRunner extends TaskRunner {
// Missing JS natives // Missing JS natives
btoa, btoa,
atob, atob,
TextDecoder,
TextDecoderStream,
TextEncoder,
TextEncoderStream,
FormData,
}; };
} }

View file

@ -42,6 +42,8 @@ export interface RPCCallObject {
const VALID_TIME_MS = 1000; const VALID_TIME_MS = 1000;
const VALID_EXTRA_MS = 100; const VALID_EXTRA_MS = 100;
const DEFAULT_MAX_PAYLOAD_SIZE = 1024 * 1024 * 1024;
export abstract class TaskRunner { export abstract class TaskRunner {
id: string = nanoid(); id: string = nanoid();
@ -74,6 +76,9 @@ export abstract class TaskRunner {
headers: { headers: {
authorization: `Bearer ${grantToken}`, 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('message', this.receiveMessage);
this.ws.addEventListener('close', this.stopTaskOffers); this.ws.addEventListener('close', this.stopTaskOffers);

View file

@ -141,7 +141,10 @@ export const setupRunnerServer = (restEndpoint: string, server: Server, app: App
} }
const endpoint = getWsEndpoint(restEndpoint); 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) => { server.on('upgrade', (request: TaskRunnerServerInitRequest, socket: Socket, head) => {
if (parseUrl(request.url).pathname !== endpoint) { if (parseUrl(request.url).pathname !== endpoint) {
// We can't close the connection here since the Push connections // We can't close the connection here since the Push connections

View file

@ -72,6 +72,7 @@ export class TaskRunnerProcess {
PATH: process.env.PATH, PATH: process.env.PATH,
N8N_RUNNERS_GRANT_TOKEN: grantToken, N8N_RUNNERS_GRANT_TOKEN: grantToken,
N8N_RUNNERS_N8N_URI: n8nUri, 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_BUILTIN: process.env.NODE_FUNCTION_ALLOW_BUILTIN,
NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL, NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL,
}, },
@ -84,6 +85,7 @@ export class TaskRunnerProcess {
PATH: process.env.PATH, PATH: process.env.PATH,
N8N_RUNNERS_GRANT_TOKEN: grantToken, N8N_RUNNERS_GRANT_TOKEN: grantToken,
N8N_RUNNERS_N8N_URI: n8nUri, 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_BUILTIN: process.env.NODE_FUNCTION_ALLOW_BUILTIN,
NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL, NODE_FUNCTION_ALLOW_EXTERNAL: process.env.NODE_FUNCTION_ALLOW_EXTERNAL,
// For debug logging if enabled // For debug logging if enabled

View file

@ -114,7 +114,10 @@ export class TaskRunnerServer {
a.ok(authToken); a.ok(authToken);
a.ok(this.server); 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); this.server.on('upgrade', this.handleUpgradeRequest);
} }