feat: enhance DatabaseManagerService and QueryExecuterService with timeout settings, add AxiosPlugin for HTTP requests, and update DatabasePlugin to use query method
This commit is contained in:
@ -10,15 +10,21 @@ export class Vm {
|
||||
private jail: any;
|
||||
private plugins: Plugin[];
|
||||
private isolate: ivm.Isolate;
|
||||
private timeLimit?: bigint;
|
||||
private cpuTimeLimit?: bigint;
|
||||
|
||||
constructor(configs: {
|
||||
memoryLimit: number;
|
||||
timeLimit?: bigint;
|
||||
cpuTimeLimit?: bigint;
|
||||
modules: VModule[];
|
||||
plugins: Plugin[];
|
||||
}) {
|
||||
this.memoryLimit = configs.memoryLimit;
|
||||
this.modules = configs.modules;
|
||||
this.plugins = configs.plugins;
|
||||
this.timeLimit = configs.timeLimit;
|
||||
this.cpuTimeLimit = configs.cpuTimeLimit;
|
||||
}
|
||||
|
||||
async init(): Promise<Vm> {
|
||||
@ -111,11 +117,23 @@ export class Vm {
|
||||
|
||||
const compiledScript = await this.isolate.compileScript(scriptWithResult);
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (
|
||||
this.isolate.cpuTime > this.cpuTimeLimit ||
|
||||
this.isolate.wallTime > this.timeLimit
|
||||
) {
|
||||
this.isolate.dispose();
|
||||
|
||||
rejectPromise(new Error("Script execution timed out"));
|
||||
}
|
||||
}, 500);
|
||||
|
||||
compiledScript.run(this.context);
|
||||
|
||||
try {
|
||||
return await resultPromise;
|
||||
} finally {
|
||||
clearInterval(interval);
|
||||
this.onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user