{"record":{"id":"943ce05fa3e8f9f6","repo":"flowable/flowable-engine","slug":"maximum-variablescope-time-of-maxscriptexecution","errorCode":null,"errorMessage":"Maximum variableScope time of ${maxScriptExecutionTime} ms exceeded","messagePattern":"Maximum variableScope time of (.+?) ms exceeded","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"modules/flowable-secure-javascript/src/main/java/org/flowable/scripting/secure/impl/SecureScriptContextFactory.java","lineNumber":80,"sourceCode":"\n        // Max stack depth\n        if (maxStackDepth > 0) {\n            context.setOptimizationLevel(-1); // stack depth can only be set when no optimizations are applied\n            context.setMaximumInterpreterStackDepth(maxStackDepth);\n        }\n\n        return context;\n    }\n\n    @Override\n    protected void observeInstructionCount(Context cx, int instructionCount) {\n        SecureScriptContext context = (SecureScriptContext) cx;\n\n        // Time limit\n        if (maxScriptExecutionTime > 0) {\n            long currentTime = System.currentTimeMillis();\n            if (currentTime - context.getStartTime() > maxScriptExecutionTime) {\n                throw new Error(\"Maximum variableScope time of \" + maxScriptExecutionTime + \" ms exceeded\");\n            }\n        }\n\n        // Memory\n        if (maxMemoryUsed > 0 && threadMxBeanWrapper != null) {\n\n            if (context.getStartMemory() <= 0) {\n                context.setStartMemory(threadMxBeanWrapper.getThreadAllocatedBytes(context.getThreadId()));\n            } else {\n                long currentAllocatedBytes = threadMxBeanWrapper.getThreadAllocatedBytes(context.getThreadId());\n                if (currentAllocatedBytes - context.getStartMemory() >= maxMemoryUsed) {\n                    throw new Error(\"Memory limit of \" + maxMemoryUsed + \" bytes reached\");\n                }\n            }\n\n        }\n    }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-secure-javascript/src/main/java/org/flowable/scripting/secure/impl/SecureScriptContextFactory.java#L62-L98","documentation":"The Flowable secure JavaScript sandbox (flowable-secure-javascript) enforces a wall-clock time limit on script execution. The Rhino instruction-observation hook (observeInstructionCount) periodically checks elapsed time since the script started and throws a plain java.lang.Error (not an Exception) once maxScriptExecutionTime is exceeded, immediately terminating the script. This is a deliberate sandbox kill to stop runaway/infinite-loop scripts in script tasks and listeners.","triggerScenarios":"A JavaScript script task / execution or task listener runs longer than the configured maxScriptExecutionTime (flowable.script... limit) — heavy loops, waits, or infinite loops inside the script; triggers during Rhino bytecode instruction callbacks.","commonSituations":"while(true) or unbounded loop in a script task; script doing expensive computation on large collections; too-low maxScriptExecutionTime configured for a legitimately heavy script; blocking call inside JS script.","solutions":["Fix the script: remove infinite/unbounded loops and heavy computation from the script task.","Increase the max script execution time setting if the workload is legitimately long-running.","Move long work out of the script into a service task or async job.","Catch/handle the Error at the process level so the process instance fails gracefully with a clear message."],"exampleFix":"// before: sandbox killed for running too long\nvar i = 0; while (true) { i++; }\n\n// after: bounded loop\nvar i = 0;\nwhile (i < 1000) { i++; }\nexecution.setVariable('count', i);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  script.execute(execution);\n} catch (Throwable t) {\n  if (t instanceof Error && String(t.getMessage()).startsWith(\"Maximum variableScope time of\")) {\n    throw new FlowableException(\"Script exceeded configured time limit; failing task gracefully\", t);\n  }\n  throw t;\n}","preventionTips":["Avoid unbounded loops and heavy computation in Flowable script tasks.","Move long-running work to async service tasks instead of synchronous scripts.","Size maxScriptExecutionTime realistically for your heaviest legitimate script.","Add unit tests that run production scripts under the same sandbox limits."],"tags":["javascript","scripting","sandbox","timeout","flowable"],"backgroundTag":"request-timeout","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}