fix(core): explicitly cleanup forked process task runner (#31106)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Forked process task runner cleanup is not explicitly invoked. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Forked process task runner cleanup is explicitly invoked. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
3b19cf6811
commit
480a20e3c5
@ -359,7 +359,7 @@ class RunningNodeProcess implements RunningTask {
|
|||||||
|
|
||||||
kill(signal?: NodeJS.Signals): Promise<void> {
|
kill(signal?: NodeJS.Signals): Promise<void> {
|
||||||
return new Promise<void>((res, rej) => {
|
return new Promise<void>((res, rej) => {
|
||||||
if (process.platform === 'win32' || process.platform === 'darwin') {
|
if (process.platform === 'win32') {
|
||||||
if (this.childProcess.kill(signal)) {
|
if (this.childProcess.kill(signal)) {
|
||||||
res();
|
res();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -367,6 +367,13 @@ export class ForkedProcessTaskRunner {
|
|||||||
writeFileSync(outputPath, content);
|
writeFileSync(outputPath, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup(signal?: NodeJS.Signals) {
|
||||||
|
this.processes.forEach((p) => {
|
||||||
|
p.kill(signal);
|
||||||
|
});
|
||||||
|
this.cleanUpBatchProcesses();
|
||||||
|
}
|
||||||
|
|
||||||
private setupProcessEventListeners() {
|
private setupProcessEventListeners() {
|
||||||
const messageHandler = (message: Serializable) => {
|
const messageHandler = (message: Serializable) => {
|
||||||
this.pseudoTerminals.forEach((p) => {
|
this.pseudoTerminals.forEach((p) => {
|
||||||
@ -383,30 +390,26 @@ export class ForkedProcessTaskRunner {
|
|||||||
// When the nx process gets a message, it will be sent into the task's process
|
// When the nx process gets a message, it will be sent into the task's process
|
||||||
process.on('message', messageHandler);
|
process.on('message', messageHandler);
|
||||||
|
|
||||||
const cleanUp = (signal?: NodeJS.Signals) => {
|
|
||||||
this.processes.forEach((p) => {
|
|
||||||
p.kill(signal);
|
|
||||||
});
|
|
||||||
process.off('message', messageHandler);
|
|
||||||
this.cleanUpBatchProcesses();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Terminate any task processes on exit
|
// Terminate any task processes on exit
|
||||||
process.once('exit', () => {
|
process.once('exit', () => {
|
||||||
cleanUp();
|
this.cleanup();
|
||||||
|
process.off('message', messageHandler);
|
||||||
});
|
});
|
||||||
process.once('SIGINT', () => {
|
process.once('SIGINT', () => {
|
||||||
cleanUp('SIGTERM');
|
this.cleanup('SIGTERM');
|
||||||
|
process.off('message', messageHandler);
|
||||||
// we exit here because we don't need to write anything to cache.
|
// we exit here because we don't need to write anything to cache.
|
||||||
process.exit(signalToCode('SIGINT'));
|
process.exit(signalToCode('SIGINT'));
|
||||||
});
|
});
|
||||||
process.once('SIGTERM', () => {
|
process.once('SIGTERM', () => {
|
||||||
cleanUp('SIGTERM');
|
this.cleanup('SIGTERM');
|
||||||
|
process.off('message', messageHandler);
|
||||||
// no exit here because we expect child processes to terminate which
|
// no exit here because we expect child processes to terminate which
|
||||||
// will store results to the cache and will terminate this process
|
// will store results to the cache and will terminate this process
|
||||||
});
|
});
|
||||||
process.once('SIGHUP', () => {
|
process.once('SIGHUP', () => {
|
||||||
cleanUp('SIGTERM');
|
this.cleanup('SIGTERM');
|
||||||
|
process.off('message', messageHandler);
|
||||||
// no exit here because we expect child processes to terminate which
|
// no exit here because we expect child processes to terminate which
|
||||||
// will store results to the cache and will terminate this process
|
// will store results to the cache and will terminate this process
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1004,6 +1004,7 @@ export class TaskOrchestrator {
|
|||||||
// endregion utils
|
// endregion utils
|
||||||
|
|
||||||
private async cleanup() {
|
private async cleanup() {
|
||||||
|
this.forkedProcessTaskRunner.cleanup();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
...Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
|
...Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user