fix: prevent orphaned processes from consuming 100% CPU when terminal closes (#16965)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Yuvraj Angad Singh
2026-02-27 04:47:09 +05:30
committed by GitHub
parent aa98cafca7
commit b8d6041d42
4 changed files with 234 additions and 6 deletions
+7 -4
View File
@@ -32,6 +32,8 @@ import {
registerSyncCleanup,
runExitCleanup,
registerTelemetryConfig,
setupSignalHandlers,
setupTtyCheck,
} from './utils/cleanup.js';
import {
cleanupToolOutputFiles,
@@ -319,6 +321,8 @@ export async function startInteractiveUI(
});
registerCleanup(() => instance.unmount());
registerCleanup(setupTtyCheck());
}
export async function main() {
@@ -340,6 +344,8 @@ export async function main() {
setupUnhandledRejectionHandler();
setupSignalHandlers();
const slashCommandConflictHandler = new SlashCommandConflictHandler();
slashCommandConflictHandler.start();
registerCleanup(() => slashCommandConflictHandler.stop());
@@ -646,10 +652,7 @@ export async function main() {
process.stdin.setRawMode(true);
// This cleanup isn't strictly needed but may help in certain situations.
process.on('SIGTERM', () => {
process.stdin.setRawMode(wasRaw);
});
process.on('SIGINT', () => {
registerSyncCleanup(() => {
process.stdin.setRawMode(wasRaw);
});
}