Description
When targeting wasm32-unknown-emscripten
with emscripten versions after probably emscripten-core/emscripten@c8857a6 and ASYNCIFY=1
, all async operations are extremely broken, often waking up after 0 ms or 1000 ms. This is most easily observed with emscripten_sleep
calls, but when I was running a multithreaded program with
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals'
- and linker flags (emcc)
-pthread -s PTHREAD_POOL_SIZE=4 -s PTHREAD_POOL_SIZE_STRICT=2 ASYNCIFY=1
- and
cargo build -Z build-std=std,panic_abort --target wasm32-unknown-emscripten
the same issue could also be observed when using std::sync::mpsc::Receiver::try_recv
, for example.
The call would take 1000 ms instead of returning immediately.
Note that emscripten-core/emscripten@c8857a6 mentions that it is only (mostly) reverting emscripten-core/emscripten#16966 , BUT I do not observe the issue before 16966 nor during the time that 16966 is active.
Reproducer: https://github.com/benjamin-sieffert/emscripten-sleep-bug
All the SDL interaction can be removed and the problem still persists.
Filed an issue with emscripten at first, but it seems that the problem cannot be reproduced in C.
So it must lie in the Rust-emscripten interaction somehow, even though I am only directly calling extern "C" emscripten_sleep
from Rust.
emscripten-core/emscripten#19872