Skip to content

Wait for init to exit before trying to remount the distro VHD - #41669

Draft
Blue (OneBlue) wants to merge 3 commits into
masterfrom
user/oneblue/termination-vhd-sync
Draft

Blue (OneBlue) wants to merge 3 commits into
masterfrom
user/oneblue/termination-vhd-sync

Conversation

@OneBlue

Copy link
Copy Markdown
Collaborator

Summary of the Pull Request

This change solves a race condition that has been observed in the CI. If a distribution is force-terminated, its LUN can be reused by a future instance creation while init is still in the process of unmounting its filesystem, which can fail the instance creation.

This change solves this by actually waiting for init to exit to consider that the distribution is stopped. The timeout reused the distribution start timeout for now (we can add a .wslconfig entry for it later if needed), and the timeout only logs a warning for now, so a single broken distro doesn't deadlock the entire user session

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI lite review requested due to automatic review settings September 22, 2026 00:00

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

🟡 Changes recommended

Normal instance creation can still reuse the VHD/LUN while init is unmounting, so the reported race remains unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)
What changed in this PR

Adds termination tracking so distro operations can wait for WSL2 init to exit before reusing VHDs.

Changes:

  • Tracks pending init termination events.
  • Waits during selected conversion and VHD operations.
  • Logs timeout warnings without blocking the session.
File Review
src/​windows/​service/​exe/​LxssUserSession.h Adds termination tracking state and wait APIs. Critical: normal instance creation does not wait before reusing the distro VHD/LUN.
src/​windows/​service/​exe/​LxssUserSession.cpp Implements termination tracking and waits for selected operations. Critical: the CreateInstance path still does not consume pending termination waits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +2532 to +2536
std::vector<PidTermination> pidTerminations;
for (const auto& termination : m_pidTerminations)
{
if (IsEqualGUID(termination.second.DistroId, DistroGuid))
{
/// </summary>
_Requires_lock_held_(m_instanceLock)
void _ConversionBegin(_In_ GUID DistroGuid, _In_ LxssDistributionState State);
std::vector<PidTermination> _ConversionBegin(_In_ GUID DistroGuid, _In_ LxssDistributionState State);

This branch has not been deployed

No deployments
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.

2 participants