Commit 069b8f47 authored by Tobias Koppers's avatar Tobias Koppers

await shutdown before ending pool

parent 6c632b81
......@@ -306,6 +306,7 @@ export async function turbopackBuild(): Promise<{
}
}
let shutdownPromise: Promise<void> | undefined
export async function workerMain(workerData: {
buildContext: typeof NextBuildContext
}): Promise<Awaited<ReturnType<typeof turbopackBuild>>> {
......@@ -332,5 +333,12 @@ export async function workerMain(workerData: {
setGlobal('telemetry', telemetry)
const result = await turbopackBuild()
shutdownPromise = result.shutdownPromise
return result
}
export async function waitForShutdown(): Promise<void> {
if (shutdownPromise) {
await shutdownPromise
}
}
......@@ -11,7 +11,7 @@ async function turbopackBuildWithWorker() {
try {
const worker = new Worker(path.join(__dirname, 'impl.js'), {
exposedMethods: ['workerMain'],
exposedMethods: ['workerMain', 'waitForShutdown'],
numWorkers: 1,
maxRetries: 0,
forkOptions: {
......@@ -27,8 +27,11 @@ async function turbopackBuildWithWorker() {
buildContext: prunedBuildContext,
})
// destroy worker so it's not sticking around using memory
await worker.end()
// destroy worker when Turbopack has shutdown so it's not sticking around using memory
// We need to wait for shutdown to make sure persistent cache is flushed
result.shutdownPromise = worker.waitForShutdown().then(() => {
worker.end()
})
return result
} catch (err: any) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment