From 9480b8575138ecef2ea8de46009ab8de27ef2cc7 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Thu, 29 Oct 2026 07:22:42 +0800 Subject: [PATCH] test(xhr): gate timeout-before-upload controls with preflight The first-report timeout controls assumed that an 80ms busy task would finish before the network service's 100ms reporting interval. Scheduler preemption can invalidate that assumption; fixed Chromium 152 also emits upload completion before the delayed XHR timeout when that happens. Hold a CORS preflight on a second loopback origin for the two controls that require no upload report. No body can be transmitted while the preflight is pending, regardless of task overrun. Preserve every event assertion and all 16 cases in both Window and Worker, including the normal network's positive completion/reporting cases. Abort both owned servers when the CLI run ends. Independent normal and 160ms-overrun controls match Chromium and the published-parent debug/release binaries on all 24 cases; each profile observes six held preflights and zero POST requests to the held endpoint. --- moli/tests/fetch_cli/xhr_timeout.rs | 24 ++++++++++++++++---- moli/tests/fetch_cli/xhr_upload_timeout.html | 19 ++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/moli/tests/fetch_cli/xhr_timeout.rs b/moli/tests/fetch_cli/xhr_timeout.rs index f800b812b0b..4394af98fc9 100644 --- a/moli/tests/fetch_cli/xhr_timeout.rs +++ b/moli/tests/fetch_cli/xhr_timeout.rs @@ -5,7 +5,7 @@ use axum::{ body::{Body, Bytes}, extract::Query, response::Html, - routing::{get, post}, + routing::{get, options, post}, }; use std::{collections::HashMap, convert::Infallible, time::Duration}; @@ -68,15 +68,24 @@ async fn upload_response(Query(delays): Query>, body: Bytes })) } +async fn pending_upload_preflight() -> Body { + std::future::pending().await +} + #[test] fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Result<()> { let runtime = tokio::runtime::Builder::new_multi_thread() .worker_threads(32) .enable_all() .build()?; - let (url, server) = runtime.block_on(async { + let (url, server, pending_server) = runtime.block_on(async { let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; - let url = format!("http://{}/page", listener.local_addr()?); + let pending_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let pending_origin = format!("http://{}", pending_listener.local_addr()?); + let url = format!( + "http://{}/page?pendingOrigin={pending_origin}", + listener.local_addr()? + ); let app = Router::new() .route( "/page", @@ -84,7 +93,12 @@ fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Res ) .route("/upload", post(upload_response)); let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); - Ok::<_, anyhow::Error>((url, server)) + // Hold the cross-origin preflight so these requests cannot upload, + // even if the script owner's busy task exceeds the reporting interval. + let pending_app = Router::new().route("/upload", options(pending_upload_preflight)); + let pending_server = + tokio::spawn(async move { axum::serve(pending_listener, pending_app).await.unwrap() }); + Ok::<_, anyhow::Error>((url, server, pending_server)) })?; let result = run_fetch_cli_with_args( &url, @@ -96,7 +110,9 @@ fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Res ], ); server.abort(); + pending_server.abort(); assert!(runtime.block_on(server).unwrap_err().is_cancelled()); + assert!(runtime.block_on(pending_server).unwrap_err().is_cancelled()); let output = result?; let stdout = clean_output(&output.stdout); assert!( diff --git a/moli/tests/fetch_cli/xhr_upload_timeout.html b/moli/tests/fetch_cli/xhr_upload_timeout.html index 8a432595d83..62cfda5cc28 100644 --- a/moli/tests/fetch_cli/xhr_upload_timeout.html +++ b/moli/tests/fetch_cli/xhr_upload_timeout.html @@ -1,10 +1,10 @@