diff --git a/quest/m1/test-flakes-2/README.md b/quest/m1/test-flakes-2/README.md index be9db61d9d8..bcf8a0dad5c 100644 --- a/quest/m1/test-flakes-2/README.md +++ b/quest/m1/test-flakes-2/README.md @@ -41,7 +41,6 @@ Public API: none. Wire: none. ## Required - [Redundant failover drift](/quest/m1/test-flakes-2/redundant-failover-drift.md) - a stitching TS export switches back to the surviving importer behind bufferbloat instead of failing on a stalled clock -- [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 - [macOS QUIC connects](/quest/m1/test-flakes-2/macos-quic-connect.md) - moq-tokio's loopback QUIC tests stop timing out on the macOS Platform job ## 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 c464ab21238..00000000000 --- a/quest/m1/test-flakes-2/ffi-cancel-connect.md +++ /dev/null @@ -1,20 +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. - -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..e22ceb3d631 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -6051,34 +6051,40 @@ 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 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; + // 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!( + 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))); - server.cancel(); + 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"), + ); } #[tokio::test]