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(js): node executor now correctly kills tasks when exiting #19219

Merged
merged 1 commit into from
Jun 28, 2024
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
41 changes: 21 additions & 20 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,27 @@ export async function* nodeExecutor(
tasks.push(task);
};

const stopAllTasks = async (signal: NodeJS.Signals = 'SIGTERM') => {
additionalExitHandler?.();
await currentTask?.stop(signal);
for (const task of tasks) {
await task.stop(signal);
}
};

process.on('SIGTERM', async () => {
await stopAllTasks('SIGTERM');
process.exit(128 + 15);
});
process.on('SIGINT', async () => {
await stopAllTasks('SIGINT');
process.exit(128 + 2);
});
process.on('SIGHUP', async () => {
await stopAllTasks('SIGHUP');
process.exit(128 + 1);
});

if (options.runBuildTargetDependencies) {
// If a all dependencies need to be rebuild on changes, then register with watcher
// and run through CLI, otherwise only the current project will rebuild.
Expand Down Expand Up @@ -276,26 +297,6 @@ export async function* nodeExecutor(
}
}
}

const stopAllTasks = (signal: NodeJS.Signals = 'SIGTERM') => {
additionalExitHandler?.();
for (const task of tasks) {
task.stop(signal);
}
};

process.on('SIGTERM', async () => {
stopAllTasks('SIGTERM');
process.exit(128 + 15);
});
process.on('SIGINT', async () => {
stopAllTasks('SIGINT');
process.exit(128 + 2);
});
process.on('SIGHUP', async () => {
stopAllTasks('SIGHUP');
process.exit(128 + 1);
});
});
}

Expand Down