diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 9bd7b68917..10dac3c0ea 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -2072,7 +2072,7 @@ describe.each([ await config.withEnv( { JS_PER_INVOCATION_TIMEOUT_MS: 20, - JS_PER_REQUEST_TIME_LIMIT_MS: 40, + JS_PER_REQUEST_TIMEOUT_MS: 40, }, async () => { const js = Buffer.from( diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index 7c3e8751c5..b5d468ec00 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -73,8 +73,8 @@ const environment = { FORKED_PROCESS_NAME: process.env.FORKED_PROCESS_NAME || "main", JS_PER_INVOCATION_TIMEOUT_MS: parseIntSafe(process.env.JS_PER_INVOCATION_TIMEOUT_MS) || 1000, - JS_PER_REQUEST_TIME_LIMIT_MS: parseIntSafe( - process.env.JS_PER_REQUEST_TIME_LIMIT_MS + JS_PER_REQUEST_TIMEOUT_MS: parseIntSafe( + process.env.JS_PER_REQUEST_TIMEOUT_MS ), // old CLIENT_ID: process.env.CLIENT_ID, diff --git a/packages/server/src/jsRunner/index.ts b/packages/server/src/jsRunner/index.ts index 60310585f5..90cc0e2564 100644 --- a/packages/server/src/jsRunner/index.ts +++ b/packages/server/src/jsRunner/index.ts @@ -19,7 +19,7 @@ export function init() { vm = new IsolatedVM({ memoryLimit: env.JS_RUNNER_MEMORY_LIMIT, invocationTimeout: env.JS_PER_INVOCATION_TIMEOUT_MS, - perRequestLimit: env.JS_PER_REQUEST_TIME_LIMIT_MS, + isolateAccumulatedTimeout: env.JS_PER_REQUEST_TIMEOUT_MS, }) .withContext(ctxToPass) .withHelpers() diff --git a/packages/server/src/jsRunner/vm/index.ts b/packages/server/src/jsRunner/vm/index.ts index e8422e8f5d..865aca0454 100644 --- a/packages/server/src/jsRunner/vm/index.ts +++ b/packages/server/src/jsRunner/vm/index.ts @@ -48,7 +48,7 @@ export class IsolatedVM implements VM { private vm: ivm.Context private jail: ivm.Reference private invocationTimeout: number - private perRequestLimit?: number + private isolateAccumulatedTimeout?: number private moduleHandler = new ModuleHandler() @@ -57,11 +57,11 @@ export class IsolatedVM implements VM { constructor({ memoryLimit, invocationTimeout, - perRequestLimit, + isolateAccumulatedTimeout, }: { memoryLimit: number invocationTimeout: number - perRequestLimit?: number + isolateAccumulatedTimeout?: number }) { this.isolate = new ivm.Isolate({ memoryLimit }) this.vm = this.isolate.createContextSync() @@ -73,7 +73,7 @@ export class IsolatedVM implements VM { }) this.invocationTimeout = invocationTimeout - this.perRequestLimit = perRequestLimit + this.isolateAccumulatedTimeout = isolateAccumulatedTimeout } withHelpers() { @@ -131,13 +131,11 @@ export class IsolatedVM implements VM { } execute(code: string): string { - const perRequestLimit = this.perRequestLimit - - if (perRequestLimit) { + if (this.isolateAccumulatedTimeout) { const cpuMs = Number(this.isolate.cpuTime) / 1e6 - if (cpuMs > perRequestLimit) { + if (cpuMs > this.isolateAccumulatedTimeout) { throw new ExecutionTimeoutError( - `CPU time limit exceeded (${cpuMs}ms > ${perRequestLimit}ms)` + `CPU time limit exceeded (${cpuMs}ms > ${this.isolateAccumulatedTimeout}ms)` ) } }