much improved support for background processes, avoiding termination (via SIGPIPE) or eventual blocking (e.g. due to filled OS buffers) (#586)

This commit is contained in:
Olcan
2025-05-28 14:45:46 -07:00
committed by GitHub
parent 00805cb2cd
commit 0d99398689
2 changed files with 35 additions and 30 deletions

View File

@@ -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) {