fix(core): return results after NodeChildProcessWithNonDirectOutput has already exited (#30943)

<!-- 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 -->

For some mysterious reason, calling `getResults` after killing a
continuous task causes the DTE agent process.. to exit.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

For some mysterious reason, allowing `getResults` to return results
after the Task has completed fixes the DTE agent process exiting.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Jason Jean 2025-04-30 20:25:22 -04:00 committed by GitHub
parent 91f5249fbf
commit 912a257982
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,8 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {
private exitCallbacks: Array<(code: number, terminalOutput: string) => void> =
[];
private exitCode: number;
constructor(
private childProcess: ChildProcess,
{ streamOutput, prefix }: { streamOutput: boolean; prefix: string }
@ -39,6 +41,7 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {
this.childProcess.on('exit', (code, signal) => {
if (code === null) code = signalToCode(signal);
this.exitCode = code;
for (const cb of this.exitCallbacks) {
cb(code, this.terminalOutput);
}
@ -64,6 +67,12 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {
}
async getResults(): Promise<{ code: number; terminalOutput: string }> {
if (typeof this.exitCode === 'number') {
return {
code: this.exitCode,
terminalOutput: this.terminalOutput,
};
}
return new Promise((res) => {
this.onExit((code, terminalOutput) => {
res({ code, terminalOutput });