From b0d4ac64d7f53f6d185f4d9069fc0b66ff46490c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 24 Jan 2025 16:00:25 +0100 Subject: [PATCH] Revert "fix(core): collect all logs from forked processes (#27778)" (#29740) This reverts commit c3709b2b84057166cbb94d3ce5cfc3de17252d35. The change can result in tasks hanging when underlying processes are not properly managed (can be processes created from third-party plugins or user's code). A hanging task is a more serious issue than what this was originally solving. We'll revisit this soon. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- .../forked-process-task-runner.ts | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/packages/nx/src/tasks-runner/forked-process-task-runner.ts b/packages/nx/src/tasks-runner/forked-process-task-runner.ts index 1144c9095f..a58eab0d46 100644 --- a/packages/nx/src/tasks-runner/forked-process-task-runner.ts +++ b/packages/nx/src/tasks-runner/forked-process-task-runner.ts @@ -338,53 +338,29 @@ export class ForkedProcessTaskRunner { } let outWithErr = []; - let exitCode; - let stdoutHasEnded = false; - let stderrHasEnded = false; - let processHasExited = false; - - const handleProcessEnd = () => { - // ensure process has exited and both stdout and stderr have ended before we pass along the logs - // if we only wait for the process to exit, we might miss some logs as stdout and stderr might still be streaming - if (stdoutHasEnded && stderrHasEnded && processHasExited) { - // we didn't print any output as we were running the command - // print all the collected output| - const terminalOutput = outWithErr.join(''); - const code = exitCode; - - if (!streamOutput) { - this.options.lifeCycle.printTaskTerminalOutput( - task, - code === 0 ? 'success' : 'failure', - terminalOutput - ); - } - this.writeTerminalOutput(temporaryOutputPath, terminalOutput); - res({ code, terminalOutput }); - } - }; - p.stdout.on('data', (chunk) => { outWithErr.push(chunk.toString()); }); - p.stdout.on('end', () => { - stdoutHasEnded = true; - handleProcessEnd(); - }); p.stderr.on('data', (chunk) => { outWithErr.push(chunk.toString()); }); - p.stderr.on('end', () => { - stderrHasEnded = true; - handleProcessEnd(); - }); p.on('exit', (code, signal) => { this.processes.delete(p); if (code === null) code = signalToCode(signal); - exitCode = code; - processHasExited = true; - handleProcessEnd(); + // we didn't print any output as we were running the command + // print all the collected output| + const terminalOutput = outWithErr.join(''); + + if (!streamOutput) { + this.options.lifeCycle.printTaskTerminalOutput( + task, + code === 0 ? 'success' : 'failure', + terminalOutput + ); + } + this.writeTerminalOutput(temporaryOutputPath, terminalOutput); + res({ code, terminalOutput }); }); } catch (e) { console.error(e);