From 92e6d8c858f669badcb05e373d55065c7c56960a Mon Sep 17 00:00:00 2001 From: srojk34 <286497132+srojk34@users.noreply.github.com> Date: Thu, 18 Jun 2026 14:58:01 +0300 Subject: [PATCH] fix(desktop): dispose open PTY sessions in before-quit handler The `before-quit` handler tears down the bootstrap controller, preview watchers, and the Python backend but never disposes live PTY sessions. When `app.quit()` proceeds to `FreeEnvironment()`, node-pty's `ThreadSafeFunction::CallJS` callback fires on a half-torn-down environment, throws a C++ exception that can no longer be caught, and the process aborts (microsoft/node-pty#904). Iterate `terminalSessions` and call `disposeTerminalSession()` (which already calls `pty.kill()` + deletes the map entry) before killing the backend, so the ThreadSafeFunctions are removed before teardown begins. Closes #48335 --- apps/desktop/electron/main.cjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/desktop/electron/main.cjs b/apps/desktop/electron/main.cjs index c8e31becf6e..be89c6c91cf 100644 --- a/apps/desktop/electron/main.cjs +++ b/apps/desktop/electron/main.cjs @@ -6551,6 +6551,12 @@ app.on('before-quit', () => { flushDesktopLogBufferSync() closePreviewWatchers() + // Kill open PTYs before environment teardown to avoid the node-pty#904 + // ThreadSafeFunction SIGABRT race. + for (const id of [...terminalSessions.keys()]) { + disposeTerminalSession(id) + } + if (hermesProcess && !hermesProcess.killed) { hermesProcess.kill('SIGTERM') }