Wait for init to exit before trying to remount the distro VHD - #41669
Draft
Blue (OneBlue) wants to merge 3 commits into
Draft
Blue (OneBlue) wants to merge 3 commits into
Blue (OneBlue) wants to merge 3 commits into
Conversation
Contributor
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.
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); |
6 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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