镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

bug(pty): the main process leaks PTY masters until macOS runs out (509/511 after 13h) #1437

Description

@Juliusolsson05

Evidence (2026-09-27 14:30Z, packaged app, main pid 94543, uptime 13h26m)

Expected

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).

🤖 Generated with Claude Code

Activity

  1. Juliusolsson05 commented on Sep 27, 2026

    @Juliusolsson05
    OwnerAuthor

    Root cause found; fix in #1439.

    node-pty 1.1.0 (our pinned version, still npm latest) leaks one /dev/ptmx per spawn on macOS. In src/unix/pty.cc pty_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.

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sev:P1Core flow broken or badly degradedtype:bugSomething works wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions