Stream: wasi

Topic: Flushing stdout in wasi/p3


view this post on Zulip Tomasz Andrzejak (Jun 15 2026 at 12:27):

Hey :wave:

What's the recommended way of flushing stdout when using wasi/p3? In p2 we have explicit functions like blocking-write-and-flush. The stdout writes are line buffered by default and I don't see anything in wasmtime p3 implementation that would actually call flush, not even on drop or stream close.

https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi/src/p3/cli/host.rs#L92

Writer's poll_flush exists but it's never called. Am I missing something?

I could workaround this by using https://docs.rs/wasmtime-wasi/45.0.1/wasmtime_wasi/struct.WasiCtxBuilder.html#method.stdout and provide my flushing stream implementation but I doubt that this is the intended way of solving the issue?

Of course, I'm happy to prepare a patch if we think that's an actual gap, thanks!

view this post on Zulip Alex Crichton (Jun 15 2026 at 14:23):

WASI-wise there's no flush operation on streams, bytes have either been acknowledged-to-be-sent or not. Implementation-wise though this is something we need to navigate, and are you seeing data not get printed to stdout?

view this post on Zulip Tomasz Andrzejak (Jun 15 2026 at 15:08):

Yes, let me create a repro -- it is tricky doing with wasmtime p3 test harness because it captures stdout on process exit which flushes and masks the behavior. I need something more "interactive".

view this post on Zulip Tomasz Andrzejak (Jun 15 2026 at 17:05):

A test with a potential fix:

https://github.com/bytecodealliance/wasmtime/pull/13654

view this post on Zulip Joel Dice (Jun 15 2026 at 17:21):

I recall some informal discussion of adding a stream.lull intrinsic to the CM which would mean "there's probably not more data coming for a while, so this would be a good time to flush if applicable". Luke may be able to describe that in more detail when he's back from his vacation.

view this post on Zulip Alex Crichton (Jun 15 2026 at 17:24):

for now though I believe this patch/fix are correct, it's tokio buffering things we didn't realize


Last updated: Jul 29 2026 at 05:03 UTC