Fix opening directories failing on Windows when fdFlags contains NONBLOCK #6348
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.
Description
We were testing the new wasmtime 8.0.1 on Windows and are getting "Permission denied" errors opening directories, while reading files under those directories work fine.
Test Case
The issue is reproducible using the below rust program (built as lister.wasm in the snippets) that directly calls opendir:
Steps to Reproduce
Build a wasm module using the test case snippet, and invoke it pointing to a directory using wasmtime-8.0.1 on Windows:
The same command works when using 8.0.0:
Versions and Environment
Wasmtime version or commit: wasmtime 8.0.1
Operating system: Windows 10
Architecture: x86_64
Extra details
The bug seems to be related to the changes in #6163. The code is failing here:
https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-common/cap-std-sync/src/dir.rs#L93
Which was not previously applied to directories. That results on the directory being reopened which ends up calling Windows ReOpenFile, and that returns a "Access denied".
We have "fixed" the issue by moving the code to be executed only for files, but that may not be the best solution. It would be great of you could give us some tips if that is not the proper solution to improve the patch.