Skip to content

Commit

Permalink
fix(gatsby): shut down worker pool after html generation (#32366)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladar committed Jul 14, 2021
1 parent b9236e1 commit 8cba0b9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/gatsby/src/commands/build.ts
Expand Up @@ -226,6 +226,7 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
workerPool,
buildSpan,
})
const waitWorkerPoolEnd = Promise.all(workerPool.end())

telemetry.addSiteMeasurement(`BUILD_END`, {
pagesCount: toRegenerate.length, // number of html files that will be written
Expand All @@ -246,6 +247,12 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
// This could occur due to queries being run which invoke sharp for instance
await waitUntilAllJobsComplete()

try {
await waitWorkerPoolEnd
} catch (e) {
report.warn(`Error when closing WorkerPool: ${e.message}`)
}

// Make sure we saved the latest state so we have all jobs cached
await db.saveState()

Expand All @@ -255,7 +262,6 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {

buildSpan.finish()
await stopTracer()
workerPool.end()
buildActivity.end()

if (program.logPages) {
Expand Down

0 comments on commit 8cba0b9

Please sign in to comment.