emscripten-core / emscripten-core/emscripten
Emscripten calling fetch from pthread seems to hang forever.
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.46-git
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 75501f53624de92aafce2f1da698b249a7293dc7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.46/libexec/llvm/bin
Hi it might be that I am just missing something completely. But I have this snippet of code here and no matter wat EMSCRIPTEN_FETCH_* attribute I slap on there the fetch keeps blocking with no sight of progress. Even if the minimal case with callbacks just seems to block forever. No traffic in the network tab no breakpoint in the JS start_fetch or the others. Quite simply one hell to debug.
Is this something I am doing wrong or is it emscripten doing something that I don't see. request_t and response_t are just wrappers over the emscripten_fetch_t*.
Off course compiled with -sUSE_PTHREADS=1 and -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency. Have to mention that this is with MEMORY_GROWTH but up until now this has not been a performance problem at all.
```
inline std::optional _send(request_t& _req) {
auto& req = *(_request_t*) _req.handle();
// main thread.
std::string url = (req.url.Protocol.empty() && req.url.Host.empty()) ? req.url.createPath(false) : req.url.toString();
req.attr.userData = &_req;
req.attr.attributes = EMSCRIPTEN_FETCH_TO_MEMORY | EMSCRIPTEN_FETCH_SYNCHRONOUS;
// Use a promise and a future to communicate data between threads
std::promise promise;
std::future future = promise.get_future();
// Create a worker thread
std::thread workerThread([&]() {
auto fetch = emscripten_fetch(&req.attr, url.c_str());
promise.set_value(fetch); // Set the data for the main thread
});
auto fetch = future.get();
workerThread.join();
return new _response_t { fetch };
}
```
Thanks in advance,
Contributor guide
Assessment
This issue has not been assessed yet.