{"record":{"id":"94d7bc3efd0c029a","repo":"Budibase/budibase","slug":"js-request-timeout-error","errorCode":"JS_REQUEST_TIMEOUT_ERROR","errorMessage":"CPU time limit exceeded (${cpuMs}ms > ${this.isolateAccumulatedTimeout}ms)","messagePattern":"CPU time limit exceeded \\((.+?)ms > (.+?)ms\\)","errorType":"exception","errorClass":"JsRequestTimeoutError","httpStatus":null,"severity":"error","filePath":"packages/server/src/jsRunner/vm/isolated-vm.ts","lineNumber":181,"sourceCode":"\n    const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS)\n\n    const script = this.isolate.compileScriptSync(\n      `${bsonPolyfills};${bsonSource}`\n    )\n    script.runSync(this.vm, { timeout: this.invocationTimeout, release: false })\n    new Promise(() => {\n      script.release()\n    })\n\n    return this\n  }\n\n  execute(code: string): any {\n    if (this.isolateAccumulatedTimeout) {\n      const cpuMs = Number(this.isolate.cpuTime) / 1e6\n      if (cpuMs > this.isolateAccumulatedTimeout) {\n        throw new JsRequestTimeoutError(\n          `CPU time limit exceeded (${cpuMs}ms > ${this.isolateAccumulatedTimeout}ms)`\n        )\n      }\n    }\n\n    code = `\n      try {\n        results = {}\n        results['${this.runResultKey}']=${this.codeWrapper(code)}\n      } catch (e) {\n        results['${this.runErrorKey}']=e\n      }\n    `\n\n    const script = this.isolate.compileScriptSync(code)\n\n    script.runSync(this.vm, { timeout: this.invocationTimeout, release: false })\n    new Promise(() => {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/jsRunner/vm/isolated-vm.ts#L163-L199","documentation":"The isolated-vm JS runner enforces a cumulative CPU-time budget per isolate. Before executing code, execute() compares the isolate's consumed cpuTime (converted to ms) against isolateAccumulatedTimeout and throws JsRequestTimeoutError (code JS_REQUEST_TIMEOUT_ERROR) when the budget is exhausted, preventing runaway scripts from consuming host CPU.","triggerScenarios":"Calling execute() on an isolate whose accumulated CPU time already exceeds isolateAccumulatedTimeout — e.g. many prior executions on the same isolate consumed the CPU budget, or the configured limit is very low so even modest scripts trip it.","commonSituations":"Long-lived isolate reused across many requests slowly exhausting its CPU budget; too-low timeout config in production; a single expensive script burning most of the budget so subsequent cheap calls fail; CPU throttling in containers inflating measured CPU time.","solutions":["Increase the isolateAccumulatedTimeout / CPU limit configuration to a value suited to your workloads.","Recycle the isolate (create a fresh one) once its CPU budget is consumed instead of reusing it.","Profile and optimize the user JS executing on the isolate to reduce CPU consumption.","Distribute load across multiple isolates so no single one exhausts its budget."],"exampleFix":"// before: one shared isolate reused until budget exhausted\nconst runner = getSharedIsolate()\nrunner.execute(code) // JsRequestTimeoutError after budget used\n// after: recycle isolate when CPU budget is spent\nif (runner.cpuTimeMs() > runner.limitMs()) runner = createIsolate()\nrunner.execute(code)","handlingStrategy":"try-catch","validationCode":"// Check remaining CPU budget before executing\nconst cpuMs = Number(isolate.cpuTime) / 1e6\nif (cpuMs > isolateAccumulatedTimeout) {\n  isolate = createNewIsolate() // recycle before execute()\n}","typeGuard":"function isCpuTimeout(err: unknown): err is Error & { code: string } {\n  return err instanceof Error && (err as { code?: string }).code === \"JS_REQUEST_TIMEOUT_ERROR\"\n}","tryCatchPattern":"try {\n  const result = isolateVm.execute(code)\n} catch (err) {\n  if (isCpuTimeout(err)) {\n    recycleIsolate() // fresh isolate with a clean CPU budget, then retry once\n  } else { throw err }\n}","preventionTips":["Recycle isolates proactively instead of reusing them indefinitely","Set isolateAccumulatedTimeout to match realistic per-workload CPU needs","Optimize hot user JS to reduce cumulative CPU consumption","Monitor isolate cpuTime metrics and alert before the budget is exhausted"],"tags":["isolated-vm","cpu","timeout","js-runner"],"backgroundTag":"cpu-time-limit-exceeded","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}