Skip to content

Commit

Permalink
Add cleanup logic to worker.ts (#54500)
Browse files Browse the repository at this point in the history
This implements the same cleanup logic used for start-server and render-workers for the workers used during build.

It's more of a contingency as we do call `.end()` on the worker too.

Fixes #45508




Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
  • Loading branch information
timneutkens and ztanner committed Aug 26, 2023
1 parent f2766b9 commit eca06a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/next/src/lib/worker.ts
Expand Up @@ -5,6 +5,14 @@ type FarmOptions = ConstructorParameters<typeof JestWorker>[1]

const RESTARTED = Symbol('restarted')

const cleanupWorkers = (worker: JestWorker) => {
for (const curWorker of ((worker as any)._workerPool?._workers || []) as {
_child?: ChildProcess
}[]) {
curWorker._child?.kill('SIGINT')
}
}

export class Worker {
private _worker: JestWorker | undefined

Expand Down Expand Up @@ -123,6 +131,7 @@ export class Worker {
if (!worker) {
throw new Error('Farm is ended, no more calls can be done to it')
}
cleanupWorkers(worker)
this._worker = undefined
return worker.end()
}
Expand All @@ -132,6 +141,7 @@ export class Worker {
*/
close(): void {
if (this._worker) {
cleanupWorkers(this._worker)
this._worker.end()
}
}
Expand Down

0 comments on commit eca06a5

Please sign in to comment.