You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(pty): the main process leaks PTY masters until macOS runs out (509/511 after 13h) #1437
Closing, reloading or replacing an agent or terminal closes its PTY master. The number of open ptmx fds tracks the number of live sessions.
Next
Find which close or replace path skips pty.kill() / fd close (node-pty). Pin it with a test that counts open ptmx fds before and after N create/close/reload cycles.
Workaround: restart the app (it frees all masters).
node-pty 1.1.0 (our pinned version, still npm latest) leaks one /dev/ptmx per spawn on macOS. In src/unix/pty.ccpty_posix_spawn, the low_fds loop opens a ptmx and breaks at count == 0 whenever stdio is open (always, in Electron). The cleanup, for (; count > 0; count--) close(low_fds[count]), never closes low_fds[0].
It matches the live evidence (main pid 94543): 506 /dev/ptmx fds, but only 16 slave fds, and those are exactly the 16 ttys with a live process. The orphans have no slave and no process, which is the low_fds[0] signature. It is not a session-lifecycle bug in our close or reload paths: every spawn leaks, whatever happens to the session afterwards.
#1439 ports #882 as a sha256-guarded source patch in postinstall, before electron-rebuild, and pins node-pty to 1.1.0. Until a build with it ships, every spawn still leaks, and only an app restart frees the table.
Activity
Juliusolsson05 commentedon Sep 27, 2026
Root cause found; fix in #1439.
node-pty 1.1.0 (our pinned version, still npm
latest) leaks one/dev/ptmxper spawn on macOS. Insrc/unix/pty.ccpty_posix_spawn, thelow_fdsloop opens a ptmx and breaks atcount == 0whenever stdio is open (always, in Electron). The cleanup,for (; count > 0; count--) close(low_fds[count]), never closeslow_fds[0].It matches the live evidence (main pid 94543): 506
/dev/ptmxfds, but only 16 slave fds, and those are exactly the 16 ttys with a live process. The orphans have no slave and no process, which is thelow_fds[0]signature. It is not a session-lifecycle bug in our close or reload paths: every spawn leaks, whatever happens to the session afterwards.Upstream: microsoft/node-pty#882 ("fix: /dev/ptmx leak on macOS", for microsoft/vscode#182212). It shipped only in 1.2.0-beta.10 and later.
#1439 ports #882 as a sha256-guarded source patch in postinstall, before electron-rebuild, and pins node-pty to 1.1.0. Until a build with it ships, every spawn still leaks, and only an app restart frees the table.
🤖 Generated with Claude Code