Add an extra JS execution time limit check to prevent creating unnecesary VM context.

This commit is contained in:
Sam Rose 2024-01-04 10:10:00 +00:00
parent eabe74a2c1
commit 68468fadb3
No known key found for this signature in database
2 changed files with 5 additions and 2 deletions

View File

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

View File

@ -18,13 +18,16 @@ export function init() {
bbCtx.jsExecutionTracker = bbCtx.jsExecutionTracker =
timers.ExecutionTimeTracker.withLimit(perRequestLimit) timers.ExecutionTimeTracker.withLimit(perRequestLimit)
} }
track = bbCtx.jsExecutionTracker.track.bind(bbCtx.jsExecutionTracker)
span?.addTags({ span?.addTags({
js: { js: {
limitMS: bbCtx.jsExecutionTracker.limitMs, limitMS: bbCtx.jsExecutionTracker.limitMs,
elapsedMS: bbCtx.jsExecutionTracker.elapsedMS, 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)
} }
} }