Skip to content

fix: harden process matching during updates - #71

Draft
Dmitriy Vasyura (dmitrivMS) wants to merge 3 commits into
mainfrom
dev/dmitriv/harden-process-handling
Draft

fix: harden process matching during updates#71
Dmitriy Vasyura (dmitrivMS) wants to merge 3 commits into
mainfrom
dev/dmitriv/harden-process-handling

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • resolve candidate processes by launch name and installation directory before waiting or requesting termination rights
  • use QueryFullProcessImageNameW with limited query access so the 32-bit updater can inspect 64-bit processes
  • hold process handles across the wait to prevent PID reuse and access-denied polling races
  • correctly check TerminateProcess failures and wait for confirmed process exit
  • cover same-name processes in other installations and the Code.exe to old_Code.exe rename flow

Issue

Fixes microsoft/vscode#76641.

Supersedes #28

This supersedes #28, which ignores ERROR_ACCESS_DENIED after requesting query and termination rights before establishing whether a same-named process belongs to this installation. That approach can still wait on every Code.exe from other users for 30 seconds, and it can hide a real termination failure for the target installation.

This PR instead queries process identity first with PROCESS_QUERY_LIMITED_INFORMATION, filters by the executable's launch name and installation directory, and only requests termination rights for verified targets. It also uses a cross-bitness-safe path API and preserves actionable termination errors.

The launch-name plus directory match is intentional: Windows updates the image path after Code.exe is renamed to old_Code.exe, while Toolhelp preserves the original launch name.

Related issues

This may also help variants reported in:

Validation

  • cargo check --target i686-pc-windows-msvc
  • cargo test --target i686-pc-windows-msvc (23 passed)
  • process tests run from the i686 updater test binary against an x64 helper, covering the cross-bitness path

Resolve running processes by executable launch name and installation directory before waiting or terminating them. Use cross-bitness-safe path queries, held process handles, and reliable termination checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Windows process detection and termination in the updater by identifying candidate processes using both launch name and installation directory, using a cross-bitness-safe image path query, and holding process handles to avoid PID-reuse races.

Changes:

  • Introduces handle-owned process matching (launch name + install directory) using QueryFullProcessImageNameW and case-insensitive ordinal comparisons.
  • Reworks wait/terminate flow to hold process handles across waits and to validate TerminateProcess failures + confirm exit via waits.
  • Expands/updates tests to cover same-name processes at other paths and executable rename scenarios.
Show a summary per file
File Description
src/process.rs Refactors process enumeration/matching and termination logic; adds handle ownership, cross-bitness path querying, and expanded process-behavior tests.
Cargo.toml Updates windows-sys feature set to support ordinal string comparison used by the new matching logic.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/process.rs
Use Unicode-aware Windows path comparison for candidate names and normalize path separators component-wise. Add direct and integration coverage for different installations and the executable replacement flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Update detects code.exe instances from other users with seperate install folders

2 participants