Fix random "ERROR_FILE_NOT_FOUND" when unmounting with absolute path#40092
Open
chemwolf6922 wants to merge 2 commits intomasterfrom
Open
Fix random "ERROR_FILE_NOT_FOUND" when unmounting with absolute path#40092chemwolf6922 wants to merge 2 commits intomasterfrom
chemwolf6922 wants to merge 2 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent ERROR_FILE_NOT_FOUND failures when unmounting a VHD by an absolute path without the \\?\ prefix, by retrying the detach using a normalized path representation.
Changes:
- Retry
DetachDiskwith a normalized/full path onERROR_FILE_NOT_FOUND(not only for relative paths), to handle\\?\prefix mismatches. - Update the inline comment to reflect the broadened retry behavior.
Comments suppressed due to low confidence (1)
src/windows/common/WslClient.cpp:1226
- The unconditional retry normalizes the disk argument via filesystem::GetFullPath(), which only works for real filesystem paths. If the user passes a non-filesystem disk identifier (e.g. passthrough paths like "\.\PHYSICALDRIVE…") and DetachDisk returns ERROR_FILE_NOT_FOUND, GetFullPath will throw (often ERROR_INVALID_NAME), changing the user-visible failure from ERROR_FILE_NOT_FOUND to a different error. Consider making normalization best-effort (catch/ignore GetFullPath failures and fall back to the original HRESULT), or gate the retry to VHD/filesystem-style paths only.
// Retry with the normalized path to handle relative paths and \\?\ prefix mismatches.
if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
// retry dismounting with the absolute path
const auto absoluteDisk = wsl::windows::common::filesystem::GetFullPath(filesystem::UnquotePath(disk).c_str());
value = service.DetachDisk(absoluteDisk.c_str());
benhillis
reviewed
Apr 3, 2026
Member
|
Hey @chemwolf6922 👋 — Following up on this PR. CI is all green and it's a nice targeted fix. There's 1 unresolved review question from @benhillis asking why the bug is non-deterministic — could you provide a response when you get a chance? That should help move this toward approval. |
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
Fix this random issue where sometimes unmount with the absolute path results in ERROR_FILE_NOT_FOUND
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
This PR adds the MountTests::MountTests::AbsolutePathVhdUnmountAfterVMTimeout test case. This test case waits for the VM to timeout before unmounting the vhd. Which will trigger the original issue w/o this patch.