Skip to content

fix: process leaks in extensionHostConnection#319223

Open
SimonSiefke wants to merge 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-ssh-2
Open

fix: process leaks in extensionHostConnection#319223
SimonSiefke wants to merge 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-ssh-2

Conversation

@SimonSiefke
Copy link
Copy Markdown
Contributor

Fixes #211462.

Details

When the connection closes, the extension host sends a disconnect message, and then closes the socket. The remote agent host, receives the disconnect message, starts its graceful cleanup but then the socket close event comes which immediately triggers extHostSocket.destroy() before the graceful cleanup is finished

Change

The change tries to ensure the extHostSocket gets shutdown gracefully, so that the cleanup code and still run and finish.

Before

When opening a new window and connecting it to SSH and then closing it 3 times, the number of processes seems to increase each time:

{
  "processCount": {
    "after": 33,
    "before": 10
  },
  "isLeak": true
}

After

When opening a new window and connecting it to SSH and then closing it 3 times, the number of processes seems to stay constant:

{
  "processCount": {
    "after": 13,
    "before": 13
  },
  "isLeak": false
}

Copilot AI review requested due to automatic review settings May 31, 2026 22:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates extension host socket disposal to perform a graceful shutdown rather than an immediate destroy, aiming to reduce abrupt termination during cleanup.

Changes:

  • Replace extHostSocket.destroy() with a conditional extHostSocket.end() on dispose.
  • Add guards to avoid ending an already-destroyed or already-ended socket.

Comment on lines +166 to +168
if (!extHostSocket.destroyed && !extHostSocket.writableEnded) {
extHostSocket.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Number of processes increases every time remote window is reloaded

3 participants