fix(pty): kill orphaned PTY when TerminalProcess constructor throws#3745
Merged
gregpriday merged 3 commits intodevelopfrom Mar 19, 2026
Merged
fix(pty): kill orphaned PTY when TerminalProcess constructor throws#3745gregpriday merged 3 commits intodevelopfrom
gregpriday merged 3 commits intodevelopfrom
Conversation
Collaborator
Author
|
Review status: Rebased and ready
|
- Extract computeSpawnContext() helper into terminalSpawn.ts - Move acquirePtyProcess() call from TerminalProcess constructor to PtyManager.spawn() - Pass pre-acquired ptyProcess and SpawnContext into TerminalProcess constructor - Wrap constructor call in try/catch that kills the PTY on failure - Add regression tests for spawn failure cleanup - Update all existing TerminalProcess tests for new constructor signature
…tests - Mock via barrel module ../pty/index.js instead of direct file - Use class syntax so mock works as constructor
- Assert ptyProcess.kill() called in kill-also-throws test case - Add test for acquirePtyProcess throwing before constructor
0b5d55a to
11f5a69
Compare
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
new TerminalProcess(...)inPtyManager.spawn()with try/catch that kills the raw PTY process if the constructor throws after spawningspawnPtyProcess()function so the raw process handle is available for cleanup before it gets buried inside the constructorResolves #3688
Changes
electron/services/PtyManager.ts— try/catch around TerminalProcess construction; kills raw PTY on failure and logs contextelectron/services/pty/terminalSpawn.ts— newspawnPtyProcess()extracted from TerminalProcess, accepts raw pty process as parameterelectron/services/pty/TerminalProcess.ts— constructor now receives a pre-spawned PTY process instead of spawning internallyelectron/services/pty/__tests__/PtyManager.spawnFailure.test.ts— new test suite for orphan preventionTesting