Skip to content

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

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

Blue (OneBlue) wants to merge 8 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 thread src/windows/service/exe/LxssUserSession.cpp
Comment thread src/windows/service/exe/LxssUserSession.h
Copilot AI review requested due to automatic review settings September 22, 2026 17:50

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

PID reuse can associate exit notifications with the wrong distro, and unregister can still eject the VHD before init exits.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread src/windows/service/exe/LxssUserSession.cpp
Copilot AI review requested due to automatic review settings September 22, 2026 20:02

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

Unresolved termination ordering and default-distribution selection issues remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread src/windows/service/exe/LxssUserSession.cpp
Copilot AI review requested due to automatic review settings September 23, 2026 19:08

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

🔵 Needs a closer look

An unregister cleanup path can still delete the VHD before init has exited.

Review effort: Lite
Findings: None

Resolved since last review (1)

@OneBlue
Blue (OneBlue) marked this pull request as ready for review September 23, 2026 22:22
@OneBlue
Blue (OneBlue) requested a review from a team as a code owner September 23, 2026 22:22
@benhillis
Ben Hillis (benhillis) requested a balanced review from Copilot September 29, 2026 21:12

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

🔵 Needs a closer look

The cross-process protocol and concurrent VM lifecycle changes warrant final human validation.

Review effort: Balanced
Findings: None

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

Timed-out termination records remain active and repeatedly delay subsequent operations.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread src/windows/service/exe/LxssUserSession.cpp

@benhillis Ben Hillis (benhillis) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A timed-out termination remains in m_pidTerminations, so each later launch or conversion waits the full timeout again. Please make a timed-out record non-waitable while retaining whatever identity is needed to correlate a late exit.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 23:06

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

🔵 Needs a closer look

The concurrency-sensitive VM lifecycle and host/guest protocol changes warrant final human review.

Review effort: Balanced
Findings: None

Resolved since last review (1)

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

Several changed C++ lines exceed the repository’s enforced 130-column limit.

Review effort: Balanced
Findings: 4 Low severity

Open (4)

Comment thread src/linux/init/main.cpp
Comment on lines +202 to +203
int ProcessMessage(
wsl::shared::Transaction& Transaction, LX_MESSAGE_TYPE Type, gsl::span<gsl::byte> Buffer, VmConfiguration& Config, std::map<pid_t, GUID>& DistroInstances);

_Requires_lock_held_(m_instanceLock)
void LxssUserSessionImpl::_ConversionBegin(_In_ GUID DistroGuid, _In_ LxssDistributionState State)
std::vector<LxssUserSessionImpl::PidTermination> LxssUserSessionImpl::_ConversionBegin(_In_ GUID DistroGuid, _In_ LxssDistributionState State)
Comment on lines +2484 to +2485
void WslCoreVm::RegisterCallbacks(
_In_ const std::function<void(const LX_MINI_INIT_CHILD_EXIT_MESSAGE&)>& DistroExitCallback, _In_ const std::function<void(GUID)>& TerminationCallback)
Comment on lines +7470 to +7471
VERIFY_ARE_EQUAL(
LxsstuLaunchWsl(std::format(L"--install --from-file \"{}\" --no-launch --name {} --version 2", g_testDistroPath, distroName)), 0L);

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.

3 participants