Skip to content

fix: memory leak in SCM artifact commands - #338251

Merged
Ladislau Szomoru (lszomoru) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-scmArtifact-lateResults
Sep 28, 2026
Merged

Ladislau Szomoru (lszomoru) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-scmArtifact-lateResults

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

An artifact request can finish after its source control or artifact provider has been disposed. The late result still converts command arguments and adds a command store to the disposed owner. A rejected request also leaves the store created before the await undisposed.

Change

Check the original provider's lifetime and cancellation after the request finishes. Create the command store only after that check, so rejected and obsolete requests cannot leave command entries behind.

Before

Opening delayed SCM artifacts, disposing the source control, and completing the pending request 37 times adds 37 old command-argument objects.

before

After

No more artifact-command argument growth is detected in the same 37-cycle test. The matching command-cache entries stay at zero.

Test Video

Seven delayed artifact request and source-control disposal cycles in the Repositories view.

test.mp4

AI disclosure: Model: GPT 6 Astra. Worktime: 22 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 19:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The lifecycle guard addresses the leak and the focused tests cover the relevant failure paths.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes SCM artifact command-cache leaks caused by late, canceled, rejected, or obsolete provider requests.

Changes:

  • Validate provider lifetime and cancellation after awaiting artifacts.
  • Delay command-store allocation until results remain valid.
  • Add lifecycle and cache-cleanup regression tests.
File Description
src/​vs/​workbench/​api/​common/​extHostSCM.ts Prevents stale requests from caching artifact commands.
src/​vs/​workbench/​api/​test/​common/​extHostSCM.test.ts Covers disposal, replacement, cancellation, rejection, and cleanup.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lszomoru

Copy link
Copy Markdown
Member

Simon Siefke (@SimonSiefke), thank you!

@lszomoru
Ladislau Szomoru (lszomoru) merged commit fee7930 into microsoft:main Sep 28, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 28, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-scmArtifact-lateResults branch September 29, 2026 11:15
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Oct 1, 2026
fix: discard stale source control artifact command results
(cherry picked from commit fee7930)
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.

5 participants