feat(pty): kill entire process tree on terminal close and app quit#3741
Merged
gregpriday merged 4 commits intodevelopfrom Mar 19, 2026
Merged
Conversation
- Add getDescendantPids() to ProcessTreeCache for bottom-up (post-order) traversal
- Add killProcessTree() helper to TerminalProcess with SIGTERM→SIGKILL escalation
- Wire kill() to use tree kill with 500ms SIGKILL timer
- Wire dispose() to use tree kill with immediate SIGKILL (process.on("exit") context)
- Add idempotency guard via killTreeTimer to prevent double SIGKILL sweeps
- Use taskkill /T /F on Windows for atomic tree kill
- Add comprehensive tests for tree kill behavior and ProcessTreeCache traversal
- Add explicit unknown[] type to .filter() callback parameters - Resolves 8 TS7006 implicit any errors in TerminalProcess.kill.test.ts
- Null out killTreeTimer after it fires to improve idempotency guard - Cancel killTreeTimer in onExit handler to prevent stale SIGKILL sweeps - Strengthen test assertions: verify getDescendantPids called with shell PID - Assert exact SIGTERM order (bottom-up) rather than just occurrence
- Windows killProcessTree uses taskkill instead of process.kill signals - Skip process tree cleanup test suite on win32 to fix CI failures
Collaborator
Author
|
Review status: Rebased and ready |
This was referenced Mar 19, 2026
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
ProcessTreeCachethat discovers child PIDs viapgrep -Pand caches them briefly to avoid redundant lookups during the SIGTERM/SIGKILL escalation sequence.Resolves #3687
Changes
electron/services/pty/TerminalProcess.ts: AddedkillProcessTree()method that sends SIGTERM to the shell and all descendants, then escalates to SIGKILL after 500ms. Replaces the oldptyProcess.kill()call in bothkill()andonUnexpectedExit(). Cleans up the kill timer indispose().electron/services/ProcessTreeCache.ts: New utility that wrapspgrep -Pwith a short TTL cache to efficiently resolve child PIDs for a given parent.electron/services/pty/__tests__/TerminalProcess.kill.test.ts: Tests covering normal kill, immediate kill, already-exited processes, undefined PID handling, and timer cleanup on dispose.electron/services/__tests__/ProcessTreeCache.test.ts: Tests for cache hit/miss behavior, TTL expiry, andpgrepfailure handling.Testing