fix: detach terminal processes on window close when other windows are open (#304649) - #307472
Open
maruthang wants to merge 2 commits into
Open
fix: detach terminal processes on window close when other windows are open (#304649)#307472maruthang wants to merge 2 commits into
maruthang wants to merge 2 commits into
Conversation
maruthang
force-pushed
the
fix/issue-304649-terminal-window-close
branch
2 times, most recently
from
April 6, 2026 10:53
eb3eb83 to
d7decd1
Compare
maruthang
force-pushed
the
fix/issue-304649-terminal-window-close
branch
from
April 6, 2026 10:58
d7decd1 to
bc22791
Compare
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @anthonykim1Matched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Updates terminal shutdown behavior to avoid immediately killing PTY processes shared across windows.
Changes:
- Detaches terminal processes when other windows remain open.
- Adds regression tests for shutdown window-count scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
terminalService.ts |
Adjusts terminal cleanup during shutdown. |
terminalService.test.ts |
Tests detach/dispose decisions by window count. |
| instance.detachProcessAndDispose(TerminalExitReason.Shutdown); | ||
| } else if (hasOtherWindowsOpen) { | ||
| // Detach without killing the process so other windows can continue using it | ||
| instance.detachProcessAndDispose(TerminalExitReason.Shutdown); |
| // When other VS Code windows are still open, only detach from the terminal processes instead | ||
| // of shutting them down. This prevents the closing window from killing PTY processes that | ||
| // other windows are still connected to via the shared pty host. | ||
| const hasOtherWindowsOpen = this._shutdownWindowCount !== undefined && this._shutdownWindowCount > 1; |
Comment on lines
+717
to
+719
| } else if (hasOtherWindowsOpen) { | ||
| // Detach without killing the process so other windows can continue using it | ||
| instance.detachProcessAndDispose(TerminalExitReason.Shutdown); |
Comment on lines
+242
to
+244
| test('should detach (not dispose) when window count is unknown but multiple windows are open', () => { | ||
| // When _shutdownWindowCount is undefined (native delegate not set), default to safe behaviour. | ||
| // This test documents that the guard only fires when the count is explicitly > 1. |
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 #304649
When multiple VS Code windows are open and one is closed, the closing window's
_onWillShutdownunconditionally callsinstance.dispose()on its terminal instances, which sends a kill signal to the PTY processes via the shared pty host. This kills terminal sessions that other windows are still connected to.Changes
In
terminalService.ts's_onWillShutdown, added a check: when_shutdownWindowCount > 1(other windows are still open), callinstance.detachProcessAndDispose()instead ofinstance.dispose(). This tears down the local IPC connection without killing the PTY process, so the process stays alive for the remaining windows.How to test
ping localhost)