fix(pty): free Rust session on kill() to stop FD leak (#974)#980
Merged
Conversation
kill() removes the pty:exit listener via _cleanup() before pty_kill, so the exit handler that calls pty_close never runs — every terminal close leaked a Rust session map entry (FDs, channels, child handle). Call pty_close explicitly after pty_kill (in finally, so a failed kill still frees the session), and add the same close to the setup-time guard path that also tears down listeners eagerly. Add a regression test asserting pty_close is invoked after kill(). Closes #974
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.
Summary
Fixes #974 —
VMarkPty.kill()leaked a Rust session map entry (FDs, channels, child handle) on every terminal close.kill()removes thepty:exitlistener via_cleanup()beforepty_kill, so when the process dies the exit handler that callspty_closenever runs. Over a long session, repeatedly opening/closing terminals exhausts FDs.Fix
kill()now callspty_closeafterpty_kill, in a.finally()so a failed kill still frees the session.pty_closeafterpty_killas well.pty_closeruns from the exit handler or directly fromkill()/guard when listeners were torn down first).Test
New
src/lib/pty.test.ts(real implementation —vi.unmock("@/lib/pty")since the global setup mocks the module):kill()invokespty_closeafterpty_killfor the same pid (exactly once on the normal path).pty_close.RED before the fix (both fail), GREEN after.
Scope
Per the issue's scope guard: only
src/lib/pty.ts+ the new sibling test. No changes tosrc-tauri/src/pty.rs(the Rust side is correct), the EventEmitter, or anything else.Verification
pnpm test src/lib/pty.test.tspassespnpm check:allgreen (lint + coverage + build + size)