From 19008bdee95b5ad1e5340e093f9b324655a51a81 Mon Sep 17 00:00:00 2001 From: Michael Anderson Date: Sun, 18 Oct 2026 08:36:24 -0500 Subject: [PATCH] Test cancelling a name lookup while it waits --- crates/fetch/src/http.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/fetch/src/http.rs b/crates/fetch/src/http.rs index 98eee913b..37ec6924c 100644 --- a/crates/fetch/src/http.rs +++ b/crates/fetch/src/http.rs @@ -573,10 +573,19 @@ mod tests_connect { let r = lookup("slow.example", slow, Instant::now() + Duration::from_millis(300), &limits(&cancel)); assert!(matches!(&r, Err(HttpError::Connect(m)) if m.contains("timed out")), "{r:?}"); assert!(t.elapsed() < Duration::from_secs(2), "{:?}", t.elapsed()); - cancel.store(true, Ordering::Relaxed); + // Cancel while the lookup is waiting on the resolver, not before it starts let t = Instant::now(); + let r = std::thread::scope(|scope| { + scope.spawn(|| { + std::thread::sleep(Duration::from_millis(100)); + cancel.store(true, Ordering::Relaxed); + }); + lookup("slow.example", slow, Instant::now() + Duration::from_secs(30), &limits(&cancel)) + }); + assert!(matches!(r, Err(HttpError::Cancelled)), "{r:?}"); + assert!(t.elapsed() >= Duration::from_millis(100) && t.elapsed() < Duration::from_secs(1), "{:?}", t.elapsed()); + // and a lookup asked for after Cancel doesn't start assert!(matches!(lookup("slow.example", slow, Instant::now() + Duration::from_secs(30), &limits(&cancel)), Err(HttpError::Cancelled))); - assert!(t.elapsed() < Duration::from_secs(1)); // a lookup that answers is used let cancel = AtomicBool::new(false); let local: SocketAddr = "127.0.0.1:9".parse().unwrap();