From 5acf62b7b9c9f9a59711cc9f2d2ac017c5ce5743 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 24 Jul 2023 14:05:22 -0700 Subject: [PATCH 1/2] preview2::pipe sink_write_stream test bugfix I didn't realize this test was racy, but it makes sense because the worker is consuming these writes in another thread. usually the foreground thread wins, but we observed the other case once in CI --- crates/wasi/src/preview2/pipe.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/wasi/src/preview2/pipe.rs b/crates/wasi/src/preview2/pipe.rs index 02e2ca0962e2..34eb8a34f03a 100644 --- a/crates/wasi/src/preview2/pipe.rs +++ b/crates/wasi/src/preview2/pipe.rs @@ -666,10 +666,13 @@ mod test { assert_eq!(len, chunk.len()); assert_eq!(state, StreamState::Open); - // But I expect this to block additional writes: + // It is possible for subsequent writes to be refused, but it is nondeterminstic because + // the worker task consuming them is in another thread: let (len, state) = writer.write(chunk.clone()).unwrap(); - assert_eq!(len, 0); assert_eq!(state, StreamState::Open); + if !(len == 0 || len == chunk.len()) { + unreachable!() + } tokio::time::timeout(REASONABLE_DURATION, writer.ready()) .await From 2afbedec752b9ab7735f1551906ea572f1fef77c Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 24 Jul 2023 15:36:07 -0700 Subject: [PATCH 2/2] fix wasi-preview2-components-sync poll_oneoff_stdio flaky test I made a typo translating the sync calls to async calls, and in the sync implementation stream::blocking_write was calling async stream::write, so it was missing the logic to make the write blocking. This would in turn cause panics in rust's std::io::stdio::print_to when writes return less than the length of the input. thank you to @silentbicycle for autoclave, which we used to reproduce this bug. --- crates/wasi/src/preview2/preview2/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasi/src/preview2/preview2/io.rs b/crates/wasi/src/preview2/preview2/io.rs index ed03fa9e77b0..ad41d0c97628 100644 --- a/crates/wasi/src/preview2/preview2/io.rs +++ b/crates/wasi/src/preview2/preview2/io.rs @@ -412,7 +412,7 @@ pub mod sync { stream: OutputStream, bytes: Vec, ) -> Result<(u64, streams::StreamStatus), streams::Error> { - in_tokio(async { AsyncHost::write(self, stream, bytes).await }) + in_tokio(async { AsyncHost::blocking_write(self, stream, bytes).await }) .map(|(a, b)| (a, b.into())) .map_err(streams::Error::from) }