fix: memory leak in pty host service#287025
Merged
Merged
Conversation
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
Fixes a memory leak in the terminal pty host controller by ensuring event/listener disposables created during pty host startup are cleaned up when the pty host is restarted.
Changes:
- Introduces a per-pty-host
DisposableStorereturned from_startPtyHostand tracked via aMutableDisposable. - Moves pty-host-scoped event registrations (connection exit, proxy events, logger client, config listener) from
this._registerto the per-pty-host store. - Updates
_ensurePtyHost,_startPtyHost,restartPtyHost, and_disposePtyHostto wire disposal throughptyHostStore.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Rename ptyHostStore to _ptyHostStore for consistency with other private fields - Simplify _startPtyHost: assign the store inside instead of returning a 3-tuple - Use _optionalProxy in _disposePtyHost to avoid re-spawning during shutdown - Reset __connection/__proxy on dispose - Add regression test that verifies listener counts stay stable across restarts
dmitrivMS
previously approved these changes
May 31, 2026
Contributor
|
@SimonSiefke Thank you! |
dmitrivMS
previously approved these changes
Jun 1, 2026
Co-authored-by: Copilot <copilot@github.com>
auto-merge was automatically disabled
June 1, 2026 07:05
Head branch was pushed to by a user without write access
dmitrivMS
approved these changes
Jun 1, 2026
aeschli
approved these changes
Jun 4, 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.
Fixes a memory leak in pty host service.
Details
When starting pty host, various events get registered using
this._register:But since there is only one instance of ptyHostService, each time when restarting the pty host, new event listeners get registered, and the number of registered disposables in
ptyHostServiceseems to grow each time.Change
The change uses a
MutableDisposableso that when the pty host is restarted, the previous event listener disposables are disposed.Before
When restarting the pty host 37 times, the number of various functions seems to grow by one each time:
After
No more leak is detected.