fix(terminal): stop interactive programs from leaking CPU after close (#12230)

This commit is contained in:
Andras Bacsai
2026-10-19 21:31:26 +02:00
committed by GitHub
parent 33b16ac345
commit 10e93c3751
+12 -1
View File
@@ -518,6 +518,8 @@ async function killPtyProcess(userId) {
// session.ptyProcess.kill() wont work here because of https://github.com/moby/moby/issues/9098
// patch with https://github.com/moby/moby/issues/9098#issuecomment-189743947
// Ctrl-C first so interactive programs (htop, top, less) quit instead of reading the kill command as keys.
session.ptyProcess.write('\x03');
session.ptyProcess.write('set +o history\nkill -TERM -$$ && exit\nset -o history\n');
setTimeout(() => {
@@ -538,10 +540,19 @@ async function killPtyProcess(userId) {
if (killAttempts < maxAttempts) {
attemptKill();
} else {
logTerminal('warn', 'PTY process still active after maximum termination attempts.', {
logTerminal('warn', 'PTY process still active after maximum termination attempts. Killing the local SSH client.', {
userId,
killAttempts,
});
// Ending the local ssh client makes sshd hang up the remote session, so nothing keeps running there.
try {
session.ptyProcess.kill();
} catch (error) {
logTerminal('error', 'Failed to kill PTY process.', {
userId,
error: error.message,
});
}
resolve(false);
}
}, 500);