While debugging tokio-rs/tokio#8034, @alexcrichton and I determined that wasmtime_wasi's wasi:clocks/monotonic-clock#{subscribe_instant,subscribe_duration} implementations can cause starvation when combined with wasi:io/poll#poll (on WASIp2). Likewise, on WASIp3, Wasmtime's waitable-set.poll implementation does not currently yield to the async runtime. Because those implementations do not yield at all for zero-duration waits, and because tokio::task::yield_now in guest code will poll with a zero timeout, the host will not yield to it's tokio runtime and give mio a chance to report readiness for one of the other pollables.
The solution is for the host (i.e. wasmtime_wasi) to call tokio::task::yield_new().await in that scenario before returning control to the guest to give mio a chance to run.
While debugging tokio-rs/tokio#8034, @alexcrichton and I determined that
wasmtime_wasi'swasi:clocks/monotonic-clock#{subscribe_instant,subscribe_duration}implementations can cause starvation when combined withwasi:io/poll#poll(on WASIp2). Likewise, on WASIp3, Wasmtime'swaitable-set.pollimplementation does not currently yield to the async runtime. 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'stokioruntime 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.