diff options
| author | Olcan <[email protected]> | 2025-05-28 14:45:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-28 14:45:46 -0700 |
| commit | 0d99398689f37c28454475bb3d25b94cdf269280 (patch) | |
| tree | 4dafad294f970d3c19046d36645481103b1f080b /packages/cli/src/ui/hooks/shellCommandProcessor.ts | |
| parent | 00805cb2cdd9786451b9a3a6746f11f47535288d (diff) | |
much improved support for background processes, avoiding termination (via SIGPIPE) or eventual blocking (e.g. due to filled OS buffers) (#586)
Diffstat (limited to 'packages/cli/src/ui/hooks/shellCommandProcessor.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/shellCommandProcessor.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.ts index e7ccefcd..74dade5e 100644 --- a/packages/cli/src/ui/hooks/shellCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/shellCommandProcessor.ts @@ -120,13 +120,19 @@ export const useShellCommandProcessor = ( stdio: ['ignore', 'pipe', 'pipe'], }); + let exited = false; let output = ''; const handleOutput = (data: string) => { - output += data; - setPendingHistoryItem({ - type: 'info', - text: output, - }); + // continue to consume post-exit for background processes + // removing listeners can overflow OS buffer and block subprocesses + // destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE + if (!exited) { + output += data; + setPendingHistoryItem({ + type: 'info', + text: output, + }); + } }; child.stdout.on('data', handleOutput); child.stderr.on('data', handleOutput); @@ -136,7 +142,8 @@ export const useShellCommandProcessor = ( error = err; }); - child.on('close', (code, signal) => { + child.on('exit', (code, signal) => { + exited = true; setPendingHistoryItem(null); output = output.trim() || '(Command produced no output)'; if (error) { |
