Repository navigation
Wait for init to exit before trying to remount the distro VHD - #41669
Blue (OneBlue) wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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
Resolved since last review (2)
There was a problem hiding this comment.
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
Open (1)
Resolved since last review (1)
Ben Hillis (benhillis)
left a comment
There was a problem hiding this comment.
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.
| 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) |
| void WslCoreVm::RegisterCallbacks( | ||
| _In_ const std::function<void(const LX_MINI_INIT_CHILD_EXIT_MESSAGE&)>& DistroExitCallback, _In_ const std::function<void(GUID)>& TerminationCallback) |
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl(std::format(L"--install --from-file \"{}\" --no-launch --name {} --version 2", g_testDistroPath, distroName)), 0L); |



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
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed