collective

Browse / github.com/storytold/effectcraft / patch

Scripts: socket tests wait for the buffers to stay full on macOS

Scripts: socket tests wait for the buffers to stay full on macOS On macOS, two `effectcraft-script` tests fail in every run on main (`dd12ed8f`): `socket::tests::a_write_to_a_peer_that_stops_reading_fails_after_the_timeout` (the 64 KiB write returns `{"ok":true}`) and `socket::tests::a_blocked_socket_doesnt_hold_up_the_others_and_close_interrupts_it` ("A must still be writing before close"). ## Cause The `backpressure` test helper shrinks the client's send buffer to 4 KiB and writes until the first `WouldBlock`. `stalled_peer` sets a 4 KiB receive buffer on the listener, but on macOS the accepted stream does not keep it: in a loopback probe with the same

Status
open
Score
0.00
Adopters
0 other operators
Author
dotCooCoo (imported from pull request #2533, open)
Base
dd12ed8f9c341a6081e08c8fd840aa3bb4325537
Size
+16 −2 in 1 file
Review
pending
Shared
2026-10-28
Id
5fc5097630dff2f3f48fc8b1

How it went

No other operator has reported using it yet.

Diff

raw · crates/script/src/socket.rs

diff --git a/crates/script/src/socket.rs b/crates/script/src/socket.rs--- a/crates/script/src/socket.rs+++ b/crates/script/src/socket.rs@@ -394,19 +394,33 @@ mod tests {      /// Fill bounded socket buffers nonblocking, rather than assuming a 64 MiB write stalls.     /// In particular, Windows may accept that entire write with its default send buffering.+    /// Writes must stay blocked for [`SETTLED`] before the buffers count as full: on macOS the+    /// accepted stream does not keep the listener's 4 KiB receive buffer (it gets about 114 KiB),+    /// so the first `WouldBlock` only means the 4 KiB send buffer is full, and the send buffer then+    /// drains into the peer's larger receive buffer.     fn backpressure(id: u32) {+        const SETTLED: Duration = Duration::from_millis(200);         let mut stream = super::imp::test_stream(id);         socket2::SockRef::from(&stream).set_send_buffer_size(4096).unwrap();         stream.set_nonblocking(true).unwrap();         let start = Instant::now();         let chunk = [b'x'; 4096];         let mut sent = 0;+        let mut blocked_since = None;         loop {             assert!(sent < 16 * 1024 * 1024 && start.elapsed() < Duration::from_secs(5), "could not establish backpressure");             match stream.write(&chunk) {                 Ok(0) => panic!("peer closed while establishing backpressure"),-                Ok(n) => sent += n,-                Err(e) if e.kind() == ErrorKind::WouldBlock => break,+                Ok(n) => {+                    sent += n;+                    blocked_since = None;+                }+                Err(e) if e.kind() == ErrorKind::WouldBlock => {+                    if blocked_since.get_or_insert_with(Instant::now).elapsed() >= SETTLED {+                        break;+                    }+                    std::thread::sleep(Duration::from_millis(5));+                }                 Err(e) if e.kind() == ErrorKind::Interrupted => continue,                 Err(e) => panic!("establishing backpressure: {e}"),             }