-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
llvm::sys::fs::access can spuriously fail on Windows when called with AccessMode::Exist #83046
Comments
@tristanlabelle managed to reproduce this:
Which fails after a few seconds on |
The reason this happens is because |
…ttributesW` fails (#83495) Fixes #83046 There is a race condition when calling `GetFileAttributesW` that can cause it to return `ERROR_ACCESS_DENIED` on a path which exists, which is unexpected for callers using this function to check for file existence by passing `AccessMode::Exist`. This was manifesting as a compiler crash on Windows downstream in the Swift compiler when using the `-index-store-path` flag (more information in apple#8224). I looked for alternate APIs to avoid bringing in `shlwapi.h`, but didn't see any good candidates. I'm not tied at all to this solution, any feedback and alternative approaches are more than welcome.
We are regularly seeing this issue surface as a compiler crash on Apple's LLVM fork: apple#8224
llvm-project/llvm/lib/Support/Windows/Path.inc
Line 617 in f1bb88b
I've been unable to reproduce this in isolation, but there seems to be some kind of race condition when calling
GetFileAttributesW
such that the call fails on a valid path withERROR_ACCESS_DENIED
. I've managed to work around this locally by avoiding the call toGetFileAttributesW
when the requested access mode isAccessMode::Exist
, and instead calling the shell functionPathFileExistsW
:I've added some logging here and verified that this function returns correctly when
GetFileAttributesW
would have failed withERROR_ACCESS_DENIED
. This function requires pulling inshlwapi.h
.I'm happy to make a PR with this patch, but I wanted to make an issue first to seek alternate solutions, or to see if anyone had insight as to why
GetFileAttributesW
is failing in this way.The text was updated successfully, but these errors were encountered: