emscripten-core / emscripten-core/emscripten
WASMFS + OPFS + SharedWorker
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I'm attempting to create a file using WASMFS + OPFS in a shared worker. I'm unable to do so due to, what looks like, an error caused by synchronously calling an async function. The 'Unexpected child type' error at line 292 of opfs_backend.cpp appears to occur during the execution of parentHandle.getFileHandle. I've compiled with pThreads, sASYNCIFY=1/2 without any success. Is there a way I can solve this?
**Minimal example**
```cpp
BackendOPFS = wasmfs_create_opfs_backend();
emscripten_console_logf("created OPFS backend: %d", BackendOPFS);
err = wasmfs_create_directory("/opfs", 0777, BackendOPFS);
ENSURE(err == 0, "failed to mount WASMFS directory. Err=%d", err);
fd = open("/opfs/foo.txt", O_RDWR | O_CREAT | O_EXCL, 0777);
ENSURE(fd > 0, "Failed to create new file %d", fd);
```
**Error occurs during execution of parentHandle.getFileHandle in this function**
```
async function wasmfsOPFSGetOrCreateFile(parent, name, create) {
let parentHandle = wasmfsOPFSDirectoryHandles.get(parent);
let fileHandle;
try {
fileHandle = await parentHandle.getFileHandle(name, {
create
})
} catch (e) {
if (e.name === "NotFoundError") {
return -20
}
if (e.name === "TypeMismatchError") {
return -31
}
err("unexpected error:", e, e.stack);
return -29
}
return wasmfsOPFSFileHandles.allocate(fileHandle)
}
```
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.4 (273f0216fede04f2445367765eaf2aabeeb60d84)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 148111fdcf0e807fe74274b18fcf65c4cff45d63)
Target: wasm32-unknown-emscripten
Thread model: posix
**Full link command and output with `-v` appended:**
--bind
--emit-tsd WebAPI.d.ts
-sWASM_BIGINT=1
-sALLOW_MEMORY_GROWTH=1
-sEXPORT_NAME=WorkOSModule
-sMODULARIZE=1
-sEXPORT_ES6=1
-sWASMFS=1
-sFS_DEBUG=1
-sASSERTIONS=2
Contributor guide
Assessment
This issue has not been assessed yet.