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

fix(core): make forked-process-task-runner robust to closed processes #14289

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class ForkedProcessTaskRunner {
this.processes.add(p);

p.once('exit', (code, signal) => {
this.processes.delete(p);
if (code === null) code = this.signalToCode(signal);
if (code !== 0) {
const results: BatchResults = {};
Expand Down Expand Up @@ -171,6 +172,7 @@ export class ForkedProcessTaskRunner {
});

p.on('exit', (code, signal) => {
this.processes.delete(p);
if (code === null) code = this.signalToCode(signal);
// we didn't print any output as we were running the command
// print all the collected output|
Expand Down Expand Up @@ -407,28 +409,36 @@ export class ForkedProcessTaskRunner {
// When the nx process gets a message, it will be sent into the task's process
process.on('message', (message: Serializable) => {
this.processes.forEach((p) => {
p.send(message);
if (p.connected) {
p.send(message);
}
});
});

// Terminate any task processes on exit
process.on('SIGINT', () => {
this.processes.forEach((p) => {
p.kill('SIGTERM');
if (p.connected) {
p.kill('SIGTERM');
}
});
// we exit here because we don't need to write anything to cache.
process.exit();
});
process.on('SIGTERM', () => {
this.processes.forEach((p) => {
p.kill('SIGTERM');
if (p.connected) {
p.kill('SIGTERM');
}
});
// no exit here because we expect child processes to terminate which
// will store results to the cache and will terminate this process
});
process.on('SIGHUP', () => {
this.processes.forEach((p) => {
p.kill('SIGTERM');
if (p.connected) {
p.kill('SIGTERM');
}
});
// no exit here because we expect child processes to terminate which
// will store results to the cache and will terminate this process
Expand Down