A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
wasip3: Add a test cancelling TCP reads (#11623)
Alex Crichton525794c6bdc9
diff --git a/Cargo.lock b/Cargo.lockindex f488ae37d5..887fc76317 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5504,9 +5504,9 @@ dependencies = [[[package]]name = "wit-bindgen"-version = "0.45.0"+version = "0.45.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"+checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36"dependencies = ["bitflags 2.6.0","futures",@@ -5516,9 +5516,9 @@ dependencies = [[[package]]name = "wit-bindgen-core"-version = "0.45.0"+version = "0.45.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1df0102d506f94732b6b517015e7e951293ed51e98f1615f15056e5e1a7a4d67"+checksum = "0467b3f0420b5d42f8b5538d21d9f416e7c8dea38d04642c7203eb5de331fd8f"dependencies = ["anyhow","heck 0.5.0",@@ -5545,9 +5545,9 @@ dependencies = [[[package]]name = "wit-bindgen-rust"-version = "0.45.0"+version = "0.45.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8e128967ed7895a41c5541bd8cd2875472caad6434e6699c1b269302a0d60b39"+checksum = "f089b7beb50fdcf0b9dc68be920843d743c00cbbd5ef1fa21c727f9b5089dac5"dependencies = ["anyhow","heck 0.5.0",@@ -5561,9 +5561,9 @@ dependencies = [[[package]]name = "wit-bindgen-rust-macro"-version = "0.45.0"+version = "0.45.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ea08d8273179bf25a7aa87fc498380f7a7f56a2df93cd1135d0ca36af1eae962"+checksum = "fdb386c24660f5803b1056efe4fca83490460c6c5ff48114cea2979946629b09"dependencies = ["anyhow","prettyplease",diff --git a/Cargo.toml b/Cargo.tomlindex f90402f828..0ef53ba797 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -325,8 +325,8 @@ io-lifetimes = { version = "2.0.3", default-features = false }io-extras = "0.18.1"rustix = "1.0.3"# wit-bindgen:-wit-bindgen = { version = "0.45.0", default-features = false }-wit-bindgen-rust-macro = { version = "0.45.0", default-features = false }+wit-bindgen = { version = "0.45.1", default-features = false }+wit-bindgen-rust-macro = { version = "0.45.1", default-features = false }# wasm-tools family:wasmparser = { version = "0.238.1", default-features = false, features = ['simd'] }diff --git a/crates/test-programs/src/bin/p3_sockets_tcp_streams.rs b/crates/test-programs/src/bin/p3_sockets_tcp_streams.rsindex 5c1a6da292..c4b82a7126 100644--- a/crates/test-programs/src/bin/p3_sockets_tcp_streams.rs+++ b/crates/test-programs/src/bin/p3_sockets_tcp_streams.rs@@ -1,8 +1,11 @@use futures::join;+use std::pin::pin;+use std::task::{Context, Poll, Waker};use test_programs::p3::wasi::sockets::types::{IpAddress, IpAddressFamily, IpSocketAddress, TcpSocket,};use test_programs::p3::wit_stream;+use wit_bindgen::StreamResult;struct Component;@@ -109,6 +112,76 @@ async fn test_tcp_shutdown_should_not_lose_data(family: IpAddressFamily) {.await;}+/// Model a situation where there's a continuous stream of data coming into the+/// guest from one side and the other side is reading in chunks but also+/// cancelling reads occasionally. Should receive the complete stream of data+/// into the result.+async fn test_tcp_read_cancellation(family: IpAddressFamily) {+ // Send 2M of data in 256-byte chunks.+ const CHUNKS: usize = (2 << 20) / 256;+ let mut data = [0; 256];+ for (i, slot) in data.iter_mut().enumerate() {+ *slot = i as u8;+ }++ setup(family, |server, client| async move {+ // Minimize the local send buffer:+ client.set_send_buffer_size(1024).unwrap();++ let (mut client_tx, client_rx) = wit_stream::new();+ join!(+ async {+ client.send(client_rx).await.unwrap();+ },+ async {+ for _ in 0..CHUNKS {+ let ret = client_tx.write_all(data.to_vec()).await;+ assert!(ret.is_empty());+ }+ drop(client_tx);+ },+ async {+ let mut buf = Vec::with_capacity(1024);+ let (mut server_rx, server_fut) = server.receive();+ let mut i = 0_usize;+ let mut consecutive_zero_length_reads = 0;+ loop {+ assert!(buf.is_empty());+ let (status, b) = {+ let mut fut = pin!(server_rx.read(buf));+ let mut cx = Context::from_waker(Waker::noop());+ match fut.as_mut().poll(&mut cx) {+ Poll::Ready(pair) => pair,+ Poll::Pending => fut.cancel(),+ }+ };+ buf = b;+ match status {+ StreamResult::Complete(n) => {+ assert_eq!(buf.len(), n);+ for slot in buf.iter_mut() {+ assert_eq!(*slot, i as u8);+ i = i.wrapping_add(1);+ }+ buf.truncate(0);+ consecutive_zero_length_reads = 0;+ }+ StreamResult::Dropped => break,+ StreamResult::Cancelled => {+ assert!(consecutive_zero_length_reads < 10);+ consecutive_zero_length_reads += 1;+ server_rx.read(Vec::new()).await;+ }+ }+ }+ assert_eq!(i, CHUNKS * 256);+ server_fut.await.unwrap();+ },+ );+ })+ .await;+}+impl test_programs::p3::exports::wasi::cli::run::Guest for Component {async fn run() -> Result<(), ()> {test_tcp_input_stream_should_be_closed_by_remote_shutdown(IpAddressFamily::Ipv4).await;@@ -122,6 +195,8 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {test_tcp_shutdown_should_not_lose_data(IpAddressFamily::Ipv4).await;test_tcp_shutdown_should_not_lose_data(IpAddressFamily::Ipv6).await;++ test_tcp_read_cancellation(IpAddressFamily::Ipv4).await;Ok(())}}diff --git a/supply-chain/audits.toml b/supply-chain/audits.tomlindex 7632920d1d..8735a687b2 100644--- a/supply-chain/audits.toml+++ b/supply-chain/audits.toml@@ -4753,6 +4753,12 @@ criteria = "safe-to-deploy"delta = "0.43.0 -> 0.45.0"notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen]]+who = "Alex Crichton <[email protected]>"+criteria = "safe-to-deploy"+delta = "0.45.0 -> 0.45.1"+notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-core]]who = "Joel Dice <[email protected]>"criteria = "safe-to-run"@@ -4764,6 +4770,12 @@ criteria = "safe-to-deploy"delta = "0.43.0 -> 0.45.0"notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-core]]+who = "Alex Crichton <[email protected]>"+criteria = "safe-to-deploy"+delta = "0.45.0 -> 0.45.1"+notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-rt]]who = "Joel Dice <[email protected]>"criteria = "safe-to-run"@@ -4780,6 +4792,12 @@ criteria = "safe-to-deploy"delta = "0.43.0 -> 0.45.0"notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-rust]]+who = "Alex Crichton <[email protected]>"+criteria = "safe-to-deploy"+delta = "0.45.0 -> 0.45.1"+notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-rust-macro]]who = "Joel Dice <[email protected]>"criteria = "safe-to-run"@@ -4791,6 +4809,12 @@ criteria = "safe-to-deploy"delta = "0.43.0 -> 0.45.0"notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-bindgen-rust-macro]]+who = "Alex Crichton <[email protected]>"+criteria = "safe-to-deploy"+delta = "0.45.0 -> 0.45.1"+notes = "The Bytecode Alliance is the author of this crate"+[[audits.wit-component]]who = "Alex Crichton <[email protected]>"criteria = "safe-to-deploy"