Fix random "ERROR_FILE_NOT_FOUND" when unmounting with absolute path#40092
Open
chemwolf6922 wants to merge 1 commit intomasterfrom
Open
Fix random "ERROR_FILE_NOT_FOUND" when unmounting with absolute path#40092chemwolf6922 wants to merge 1 commit intomasterfrom
chemwolf6922 wants to merge 1 commit 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
| // check is the result is the error code for "file not found" and the path is relative | ||
| if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) && PathIsRelative(disk)) | ||
| // Retry with the normalized path to handle relative paths and \\?\ prefix mismatches. | ||
| if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) |
Member
There was a problem hiding this comment.
Did you figure out why the result is not deterministic? That’s very odd.
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
There is already a test case MountTests::MountTests::AbsolutePathVhdUnmount for this. But since this issue is not deterministic, it does not catch the problem reliably.
Instead, I did this loop for 20 times for before and after the fix:
Before:
6 / 20 hits.
After:
0 / 20 hits.