emscripten-core / emscripten-core/emscripten
Fetch API: id returned by emscripten_fetch is always 0 in version 3.1.39
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
The [Fetch API](https://emscripten.org/docs/api_reference/fetch.html) in 3.1.39 always returns 0 for `fetch->id`. That is, `id` in the `emscripten_fetch_t` struct returned by `emscripten_fetch()` is now always 0. This breaks a **lot** of things, and should be considered a major bug.
The bug is new in 3.1.39 - it does not occur with 3.1.38.
**Version of emscripten/emsdk:**
`commit e8b64774ff1a3ddb6a013203ced27a34e70c2d8b (HEAD -> main, tag: 3.1.39, origin/main, origin/HEAD)`
> emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.39 (36f871819b566281d160470a1ec4515f379e9f77)
> clang version 17.0.0 (https://github.com/llvm/llvm-project c672c3fe05adbb590abc99da39143b55ad510538)
> Target: wasm32-unknown-emscripten
> Thread model: posix
Simplified failing example:
```cpp
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
std::strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.onsuccess = download_onsuccess;
attr.onerror = download_onerror;
emscripten_fetch_t *fetch = emscripten_fetch(&attr, "any_url");
std::cout << "Fetch ID at call: " << fetch->id << std::endl;
download_onsuccess(emscripten_fetch_t *fetch) {
std::cout << "Fetch ID on completion: " << fetch->id << std::endl;
}
```
Call this multiple times to see fetch ID is always 0 on call, but reported correctly on completion.
Note there is another issue with the Fetch API that also appears in 3.1.39 triggered by the same code above, that is possibly related: #19464
Contributor guide
Assessment
This issue has not been assessed yet.