From 96c560a6915617cfc2de1b267d29eb8a02f2dce3 Mon Sep 17 00:00:00 2001 From: Boris D Date: Tue, 14 Oct 2025 16:04:54 +0300 Subject: [PATCH] fix: add timeout handling for script execution in Vm class --- src/vm/vm.class.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vm/vm.class.ts b/src/vm/vm.class.ts index fd7feed..b5b4f24 100644 --- a/src/vm/vm.class.ts +++ b/src/vm/vm.class.ts @@ -172,16 +172,20 @@ export class Vm { `; const compiledScript = await this.isolate.compileScript(scriptWithResult); + let timer = 0n; const interval = setInterval(() => { if ( this.isolate.cpuTime > this.cpuTimeLimit || - this.isolate.wallTime > this.timeLimit + this.isolate.wallTime > this.timeLimit || + timer > this.timeLimit ) { this.isolate.dispose(); rejectPromise(new Error("Script execution timed out")); } + + timer += 500000n; }, 500); compiledScript.run(this.context);