dicej assigned dicej to issue #13040.
dicej opened issue #13040:
While debugging https://github.com/tokio-rs/tokio/issues/8034, @alexcrichton and I determined that
wasmtime_wasi'swasi:clocks/monotonic-clock#{subscribe_instant,subscribe_duration,wait_until,wait_forimplementations can cause starvation when combined withwasi:io/poll#poll(for WASIp2) orwaitable-set.wait(for WASIp3). Because those implementations do not yield at all for zero-duration waits, and becausetokio::task::yield_nowin guest code will poll with a zero timeout, the host will not yield to _it's_tokioruntime and givemioa chance to report readiness for one of the other pollables.The solution is for the host (i.e.
wasmtime_wasi) to calltokio::task::yield_new().awaitin that scenario before returning control to the guest to givemioa chance to run.
dicej added the bug label to Issue #13040.
dicej added the wasi:impl label to Issue #13040.
dicej edited issue #13040:
While debugging https://github.com/tokio-rs/tokio/issues/8034, @alexcrichton and I determined that
wasmtime_wasi'swasi:clocks/monotonic-clock#{subscribe_instant,subscribe_duration,wait_until,wait_for}implementations can cause starvation when combined withwasi:io/poll#poll(for WASIp2) orwaitable-set.wait(for WASIp3). Because those implementations do not yield at all for zero-duration waits, and becausetokio::task::yield_nowin guest code will poll with a zero timeout, the host will not yield to _it's_tokioruntime and givemioa chance to report readiness for one of the other pollables.The solution is for the host (i.e.
wasmtime_wasi) to calltokio::task::yield_new().awaitin that scenario before returning control to the guest to givemioa chance to run.
dicej commented on issue #13040:
In https://github.com/dicej/wasmtime/commit/cf7f9f725583ab698be810e350fd549ccd08f7e6 I've added tests which reliably reproduce the issue for both p2 and p3, and a fix for p2, but I'm not sure yet how to address p3 given that Wasmtime doesn't depend on Tokio, so we can't just call
tokio::task::yield_nowthere. One thought would be to add a public API so the embedder can supply their own yield function.
Darksonn commented on issue #13040:
It's worth clarifying that when Tokio yields with a duration of zero, the express purpose of doing that is to get new IO events, so I think it's important that WASI will check for them and deliver them in that scenario.
Last updated: Apr 12 2026 at 23:10 UTC