You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.IO.Directory.CreateTempSubdirectory(String prefix) fails with Success exception in wasi-wasm build #92336
using System;
using System.IO;
using System.Text;
Console.WriteLine("Hello, Wasi Console!");
using (var writer = File.Create("/tmp/test.txt")) {
writer.Write(Encoding.UTF8.GetBytes("Hello World!"));
}
var dir = Directory.CreateTempSubdirectory();
Console.WriteLine("Created temp dir: " + dir.FullName);
dotnet build
create a tmp directory in the workspace directory
wasmtime 12.0.2
run wasmtime run --mapdir /::. --env TMPDIR=/tmp obj/Debug/net8.0/wasi-wasm/wasm/for-build/tempDir.wasm
Expected behavior
Creating the temp directory works
Actual behavior
System.IO.IOException: Success
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
at Interop.ThrowIOExceptionForLastError()
at System.IO.Directory.CreateTempSubdirectoryCore(String prefix)
at System.IO.Directory.CreateTempSubdirectory(String prefix)
at Program.<Main>$(String[] args)
@pavelsavara I executed the WASM file on the VS Code WASI host implementation which offers nice tracing of host calls. The Directory.CreateTempSubdirectory() call doesn't result in any host calls, so I guess this fails inside some C# code and is falsely reported as a exception with an errno. There aren't any fd_readdir calls either before.
What I did notice as well is that the wasm code does tons of clock_time_get(id: monotonic, precision: 1) calls.
Any reason why we couldn't implement that in C# for WASI. I can understand why we can't use libc since they hardcode /tmp but Python on wasm-wasi has support for this since they come with their own mkdtemp implementation.
It would be also good to do that for emscripten build.
Because the idea of generating randomness out of timer + checking if there is file system conflict is very ugly.
We had issues with that already because of the granularity of browser timer used.
Activity
dbaeumer commentedon Sep 20, 2023
I can create a directory as well using the following code
pavelsavara commentedon Sep 20, 2023
Could be related #81210 and WebAssembly/wasi-libc#414
dbaeumer commentedon Sep 20, 2023
@pavelsavara I executed the WASM file on the VS Code WASI host implementation which offers nice tracing of host calls. The
Directory.CreateTempSubdirectory()call doesn't result in any host calls, so I guess this fails inside some C# code and is falsely reported as a exception with anerrno. There aren't anyfd_readdircalls either before.What I did notice as well is that the wasm code does tons of
clock_time_get(id: monotonic, precision: 1)calls.pavelsavara commentedon Sep 20, 2023
See
runtime/src/native/libs/System.Native/pal_io.c
Lines 850 to 852 in 32c3355
https://github.com/WebAssembly/wasi-libc/blob/ce2f157d46e04f323edf93f02c8f60069d88df96/libc-top-half/musl/include/stdlib.h#L118-L122
dbaeumer commentedon Sep 20, 2023
Any reason why we couldn't implement that in C# for WASI. I can understand why we can't use libc since they hardcode
/tmpbut Python on wasm-wasi has support for this since they come with their ownmkdtempimplementation.pavelsavara commentedon Sep 20, 2023
That's what #81210 wants I think.
It would be also good to do that for emscripten build.
Because the idea of generating randomness out of timer + checking if there is file system conflict is very ugly.
We had issues with that already because of the granularity of browser timer used.
https://github.com/emscripten-core/emscripten/blob/813a727fa77b3596c75a6d62b2fdb87365f9d75a/system/lib/libc/musl/src/temp/mkdtemp.c#L16-L19
https://github.com/emscripten-core/emscripten/blob/813a727fa77b3596c75a6d62b2fdb87365f9d75a/system/lib/libc/musl/src/temp/__randname.c#L13-L14
PR welcome.
adamsitnik commentedon Sep 22, 2023
It reminds me of
pavelsavara commentedon Sep 22, 2023
SetLastErrorFTW ? 😎ilonatommy commentedon Jul 9, 2024
blocked by WebAssembly/wasi-libc#229