fix: add timeout handling for script execution in Vm class

This commit is contained in:
Boris D
2025-10-14 16:04:54 +03:00
parent 9c924c525b
commit 96c560a691

View File

@ -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);