Clean up isolates when a request is finished.
This commit is contained in:
parent
3e84ad924d
commit
ba002f9649
|
@ -15,4 +15,5 @@ export type ContextMap = {
|
||||||
jsContext: Context
|
jsContext: Context
|
||||||
helpersModule: Module
|
helpersModule: Module
|
||||||
}
|
}
|
||||||
|
cleanup?: (() => void | Promise<void>)[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,14 @@ export function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bbCtx.isolateRefs = { jsContext, jsIsolate, helpersModule }
|
bbCtx.isolateRefs = { jsContext, jsIsolate, helpersModule }
|
||||||
|
if (!bbCtx.cleanup) {
|
||||||
|
bbCtx.cleanup = []
|
||||||
|
}
|
||||||
|
bbCtx.cleanup.push(() => {
|
||||||
|
helpersModule.release()
|
||||||
|
jsContext.release()
|
||||||
|
jsIsolate.dispose()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let { jsIsolate, jsContext, helpersModule } = bbCtx.isolateRefs!
|
let { jsIsolate, jsContext, helpersModule } = bbCtx.isolateRefs!
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { Ctx } from "@budibase/types"
|
||||||
|
import { context } from "@budibase/backend-core"
|
||||||
|
|
||||||
|
export default async (ctx: Ctx, next: any) => {
|
||||||
|
const resp = next()
|
||||||
|
|
||||||
|
const current = context.getCurrentContext()
|
||||||
|
if (current?.cleanup) {
|
||||||
|
for (let fn of current.cleanup || []) {
|
||||||
|
await fn()
|
||||||
|
}
|
||||||
|
delete current.cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
Loading…
Reference in New Issue