Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cleanup logic to worker.ts #54500

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/next/src/lib/worker.ts
Original file line number Diff line number Diff line change
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