Repository navigation
Terminals no longer leak a PTY each: node-pty 1.2.0-beta.15 - #65
Merged
Merged
Conversation
node-pty 1.1.0's macOS pty_posix_spawn opens a placeholder /dev/ptmx (low_fds) to keep the master off fds 0-2, then closes low_fds[count..1] and never low_fds[0]. In any process with 0-2 open, count is 0, so every spawn leaked one PTY until Modex quit; macOS allows 511 machine-wide. 1.2.0-beta.15 closes low_fds[0..count], the parent's slave and the exit watcher's kqueue. Its JS API is unchanged apart from an optional pixel size on resize(), and it ships the same darwin prebuilds. A real-PTY test opens and closes five terminals and counts this process's /dev/ptmx handles: 5 leaked on 1.1.0, 0 on the beta. status.md had blamed node-pty's write stream; corrected and moved to "On main, not yet released". Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused dependency update is consistent across manifests and has targeted regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Updates node-pty to fix macOS PTY descriptor leaks and adds regression coverage.
Changes:
- Pins
node-ptyto1.2.0-beta.15. - Adds a macOS PTY cleanup regression test.
- Updates project status documentation.
| File | Description |
|---|---|
package-lock.json |
Locks the updated dependency and integrity hash. |
apps/desktop/package.json |
Updates the node-pty dependency. |
apps/desktop/test/terminal-cleanup.test.ts |
Verifies closed terminals release PTYs. |
docs/status.md |
Documents the fix and stable-upgrade follow-up. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
BunsDev
added a commit
that referenced
this pull request
Oct 2, 2026
Point the PTY-leak entry at #65 instead of its branch, note that no packaged build has run the node-pty beta yet (v0.0.5's packaged e2e will be the first), and add #64's consistent cleanup-failure message. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every terminal session leaked one
/dev/ptmxuntil Modex quit. macOS allows 511 machine-wide (kern.tty.ptmx_max), so a long-running Modex could stop terminals opening anywhere on the Mac. Found while investigating the cleanup flakes (#64).Cause: node-pty 1.1.0 on macOS
pty_posix_spawn(src/unix/pty.cc) opens placeholder PTYs until one lands at fd ≥ 2, then opens the real master separately. Cleanup isfor (; count > 0; count--) close(low_fds[count]);, which never closeslow_fds[0]. In any process whose fds 0–2 are open,countis 0, so the first placeholder leaks on every spawn. Anlsoftrace confirmed it: each terminal's own master and slave close on stop, and one extra unused/dev/ptmxper spawn stays open.(
status.mdfrom #64 blamed node-pty's write stream anddestroy(). That was wrong;CustomWriteStreamshares the socket's fd. Corrected here.)Fix: pin
node-ptyto1.2.0-beta.15Upstream's beta closes
low_fds[0..count], the parent's slave fd, and the exit watcher'skqueue(also leaked once per spawn in 1.1.0). Compared with 1.1.0:pixelSizeonresize();processskipsspawn_helper.FD_CLOEXEC, and specific spawn error messages instead ofposix_spawnp failed.;spawn-helper.ccidentical.It is a pre-release.
status.mdsays to move to 1.2.0 stable when it ships. The lockfile diff is only the node-pty entry; the integrity matches the registry.Tests
/dev/ptmxhandles vialsof(macOS only). On 1.1.0 it fails (actual: 5, expected: 0); on the beta it passes.npm run build && npm run typecheck && npm test: core 15/15, desktop 147/147.playwright test e2e/terminal.spec.ts e2e/terminal-lifecycle.spec.ts e2e/release.spec.ts: 18 passed, including the bundled terminal engine starts a real PTY.Not run: a packaged (
npm run dist) build.prepare-terminal.mjssets the beta'sspawn-helperexecutable as before, andasarUnpackstill coversnode_modules/node-pty/**.🤖 Generated with Claude Code