Merge pull request #12702 from Budibase/add-extra-run-js-limit-check

Add an extra JS execution time limit check to prevent creating unnecessary VM context.
This commit is contained in:
Sam Rose 2024-01-04 11:01:22 +00:00 committed by GitHub
commit 905ea2ea6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -50,7 +50,7 @@ export class ExecutionTimeTracker {
return this.totalTimeMs
}
private checkLimit() {
checkLimit() {
if (this.totalTimeMs > this.limitMs) {
throw new ExecutionTimeoutError(
`Execution time limit of ${this.limitMs}ms exceeded: ${this.totalTimeMs}ms`

View File

@ -18,13 +18,16 @@ export function init() {
bbCtx.jsExecutionTracker =
timers.ExecutionTimeTracker.withLimit(perRequestLimit)
}
track = bbCtx.jsExecutionTracker.track.bind(bbCtx.jsExecutionTracker)
span?.addTags({
js: {
limitMS: bbCtx.jsExecutionTracker.limitMs,
elapsedMS: bbCtx.jsExecutionTracker.elapsedMS,
},
})
// We call checkLimit() here to prevent paying the cost of creating
// a new VM context below when we don't need to.
bbCtx.jsExecutionTracker.checkLimit()
track = bbCtx.jsExecutionTracker.track.bind(bbCtx.jsExecutionTracker)
}
}