Skip to content

Commit

Permalink
Ensure workers are not left open (#34503)
Browse files Browse the repository at this point in the history
This fixes #33615. If an App uses `getInitialProps`, the build function never enters [this conditional block](https://github.com/vercel/next.js/blob/a52bd712fe797b59cfd05ceaa4c33096a0c346ff/packages/next/build/index.ts#L1481-L1484) and the static worker is left open.
  • Loading branch information
kinetifex committed Feb 18, 2022
1 parent 7c103fa commit ab40370
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -1910,6 +1910,9 @@ export default async function build(
})
}

// ensure the worker is not left hanging
staticWorkers.close()

const analysisEnd = process.hrtime(analysisBegin)
telemetry.record(
eventBuildOptimize(pagePaths, {
Expand Down
9 changes: 9 additions & 0 deletions packages/next/lib/worker.ts
Expand Up @@ -85,4 +85,13 @@ export class Worker {
this._worker = undefined
return worker.end()
}

/**
* Quietly end the worker if it exists
*/
close(): void {
if (this._worker) {
this._worker.end()
}
}
}

0 comments on commit ab40370

Please sign in to comment.