From 733e328c0f2d0c435b1c0705970806e7ad9fa1bd Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 19 Oct 2026 19:12:20 -0700 Subject: [PATCH 1/4] chore: claim ffi cancel connect quest Co-Authored-By: GPT-6.1-Sol From 366379772af4b2d6a9e74e39a7972df341e0c1bf Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 19 Oct 2026 19:17:36 -0700 Subject: [PATCH 2/4] test(ffi): order pending connect cancellation in place Co-Authored-By: GPT-6.1-Sol --- quest/m1/test-flakes-2/ffi-cancel-connect.md | 14 ++++++++++++ rs/moq-ffi/src/test.rs | 23 +++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/quest/m1/test-flakes-2/ffi-cancel-connect.md b/quest/m1/test-flakes-2/ffi-cancel-connect.md index c464ab21238..5047ae02882 100644 --- a/quest/m1/test-flakes-2/ffi-cancel-connect.md +++ b/quest/m1/test-flakes-2/ffi-cancel-connect.md @@ -17,4 +17,18 @@ connect reached `established()`, so the dial can resolve before `cancel()`. can lose to a completing connect in production. - On failure, print the value the connect actually returned. +The 2026-10-20 investigation did not reproduce the reported failure: the +original fixture passed once and in 128 bounded repetitions on an unsaturated +host. Its failing return value and the historical root cause remain unknown. +A controlled two-poll diagnostic confirmed that `spawn_parked` can return a +completed call before cancellation, even when its first poll was `Pending`; +this establishes the helper's ordering gap, not the historical failure's cause. + +The fixture now polls the actual foreign connect in place, asserts `Pending`, +then cancels synchronously before its next poll. Both an unexpectedly completed +first poll and a wrong cancellation result print the actual error (or session +success). This ordering passed 128 repetitions; it does not establish that the +historical loaded-host flake is fixed. Reproduce that failure before changing +production cancellation behavior, and verify under naturally saturated load. + Public API: none, unless the race is a product bug. Wire: none. diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 58ea35e056d..6bff6cc07b6 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -6067,17 +6067,24 @@ async fn client_cancel_aborts_a_pending_connect() { }) .unwrap(); - // The server never accepts, so connect parks in established(). - let connecting = client.clone(); - let connect = spawn_parked(async move { connecting.connect(format!("https://{addr}")).await }).await; + // Keep the foreign call in place: after it parks, cancel before its next poll. + // A spawned call can finish while the helper waits for the runtime to catch up. + let mut connect = std::pin::pin!(client.connect(format!("https://{addr}"))); + let first = std::future::poll_fn(|cx| std::task::Poll::Ready(connect.as_mut().poll(cx))).await; + assert!( + first.is_pending(), + "connect resolved before cancel: {:?}", + first.map(|result| result.map(|_| "session")), + ); client.cancel(); - let connect_err = tokio::time::timeout(TIMEOUT, connect) - .await - .expect("connect task timed out") - .expect("connect task panicked"); - assert!(matches!(connect_err, Err(MoqError::Cancelled))); + let connect_err = tokio::time::timeout(TIMEOUT, connect).await.expect("connect timed out"); + assert!( + matches!(connect_err, Err(MoqError::Cancelled)), + "connect returned {:?}", + connect_err.map(|_| "session"), + ); server.cancel(); } From cbd821be5979b38962760870ac53db7f30acf1e0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 19 Oct 2026 22:35:21 -0700 Subject: [PATCH 3/4] test(ffi): confirm the connect race and complete its quest The old fixture reproduced under load (7 of 3840, all Ok(session)): the dial establishes without the server accepting, so a spawned connect can finish before cancel. The in-place poll is deterministic, so the quest is done. Co-Authored-By: Claude Opus 5.5 --- quest/m1/test-flakes-2/README.md | 1 - quest/m1/test-flakes-2/ffi-cancel-connect.md | 34 -------------------- rs/moq-ffi/src/test.rs | 4 +-- 3 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 quest/m1/test-flakes-2/ffi-cancel-connect.md diff --git a/quest/m1/test-flakes-2/README.md b/quest/m1/test-flakes-2/README.md index e9c11d41c55..a960edf2c02 100644 --- a/quest/m1/test-flakes-2/README.md +++ b/quest/m1/test-flakes-2/README.md @@ -39,7 +39,6 @@ Public API: none. Wire: none. ## Required - [moq-tokio redial tests](/quest/m1/test-flakes-2/tokio-redial.md) - the two redial tests stop assuming a dropped port stays free and stop racing 10 s deadlines -- [moq-ffi cancel during connect](/quest/m1/test-flakes-2/ffi-cancel-connect.md) - `client_cancel_aborts_a_pending_connect` orders its cancel deterministically, fixing the code if the race is real - [Flapping-peer reorder seed](/quest/m1/test-flakes-2/flapping-peer-reorder.md) - replay one drill seed on current main, and fix it or delete the quest ## Related diff --git a/quest/m1/test-flakes-2/ffi-cancel-connect.md b/quest/m1/test-flakes-2/ffi-cancel-connect.md deleted file mode 100644 index 5047ae02882..00000000000 --- a/quest/m1/test-flakes-2/ffi-cancel-connect.md +++ /dev/null @@ -1,34 +0,0 @@ -# [XS] moq-ffi cancel reliably aborts a pending connect - -## Goal - -The moq-ffi test `client_cancel_aborts_a_pending_connect` -(`rs/moq-ffi/src/test.rs`) passes reliably under load. It fails with -`assertion failed: matches!(connect_err, Err(MoqError::Cancelled))`, locally -2 of 960 runs under load; no CI hit was found. - -## Plan - -Hypothesis, unconfirmed: `spawn_parked` only guarantees one poll, not that the -connect reached `established()`, so the dial can resolve before `cancel()`. - -- Confirm the race first. -- Order the cancel deterministically: in the test, or in the code if a cancel - can lose to a completing connect in production. -- On failure, print the value the connect actually returned. - -The 2026-10-20 investigation did not reproduce the reported failure: the -original fixture passed once and in 128 bounded repetitions on an unsaturated -host. Its failing return value and the historical root cause remain unknown. -A controlled two-poll diagnostic confirmed that `spawn_parked` can return a -completed call before cancellation, even when its first poll was `Pending`; -this establishes the helper's ordering gap, not the historical failure's cause. - -The fixture now polls the actual foreign connect in place, asserts `Pending`, -then cancels synchronously before its next poll. Both an unexpectedly completed -first poll and a wrong cancellation result print the actual error (or session -success). This ordering passed 128 repetitions; it does not establish that the -historical loaded-host flake is fixed. Reproduce that failure before changing -production cancellation behavior, and verify under naturally saturated load. - -Public API: none, unless the race is a product bug. Wire: none. diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 6bff6cc07b6..abec356f219 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -6067,8 +6067,8 @@ async fn client_cancel_aborts_a_pending_connect() { }) .unwrap(); - // Keep the foreign call in place: after it parks, cancel before its next poll. - // A spawned call can finish while the helper waits for the runtime to catch up. + // The dial can establish without the server accepting, so a spawned connect may finish + // while `spawn_parked` waits for the runtime. Poll it in place and cancel before its next poll. let mut connect = std::pin::pin!(client.connect(format!("https://{addr}"))); let first = std::future::poll_fn(|cx| std::task::Poll::Ready(connect.as_mut().poll(cx))).await; assert!( From 05d4a225bb907c28d64b9af192cb8990f7907ac1 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 19 Oct 2026 23:21:00 -0700 Subject: [PATCH 4/4] test(ffi): park the cancelled connect on a silent peer A real server lets the handshake finish without accepting, so a dial preempted between spawning and its first established() check could resolve on the first poll. A bound socket that never answers keeps the connect pending until cancel, with no handshake to race. Co-Authored-By: Claude Opus 5.5 --- rs/moq-ffi/src/test.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index abec356f219..e22ceb3d631 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -6051,24 +6051,24 @@ async fn session_protocol_codes_cross_the_ffi() { } #[tokio::test] async fn client_cancel_aborts_a_pending_connect() { - let server = MoqServer::new(MoqServerConfig { - bind: Some("127.0.0.1:0".into()), - tls: localhost_tls(), - ..Default::default() - }) - .unwrap(); - let addr = server.listen().await.expect("listen failed"); + // A bound socket that never answers, so the QUIC handshake can't finish before cancel. + // A real server would not do: the dial establishes without the server accepting. + let silent = std::net::UdpSocket::bind("127.0.0.1:0").unwrap(); + let addr = silent.local_addr().unwrap(); let client = MoqClient::new(MoqClientConfig { tls: insecure_tls(), bind: Some("127.0.0.1:0".into()), once: true, + websocket: MoqWebSocketConfig { + enabled: Some(false), + delay_us: None, + }, ..Default::default() }) .unwrap(); - // The dial can establish without the server accepting, so a spawned connect may finish - // while `spawn_parked` waits for the runtime. Poll it in place and cancel before its next poll. + // Poll in place rather than spawning, so cancel lands before the next poll. let mut connect = std::pin::pin!(client.connect(format!("https://{addr}"))); let first = std::future::poll_fn(|cx| std::task::Poll::Ready(connect.as_mut().poll(cx))).await; assert!( @@ -6085,7 +6085,6 @@ async fn client_cancel_aborts_a_pending_connect() { "connect returned {:?}", connect_err.map(|_| "session"), ); - server.cancel(); } #[tokio::test]