From 1e3553843d4deb3a4d9122eb2f7a19544b8f3328 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 4 Nov 2026 15:48:59 +0700 Subject: [PATCH] Single instance: the stale-endpoint test connects to no freed port The test bound a port, freed it and then connected to it as a gone app. Tests run in parallel, so another test's listener could take that port meanwhile and accept this connection in place of its own client's, whose connection was then reset when the listener closed: the cause of the intermittent tcp_connection_is_closed_after_junk failures on Windows. The gone app is now a listener that closes without a greeting. --- apps/vectorcraft/src/single_instance.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/vectorcraft/src/single_instance.rs b/apps/vectorcraft/src/single_instance.rs index b8df2bb5a..f7026131c 100644 --- a/apps/vectorcraft/src/single_instance.rs +++ b/apps/vectorcraft/src/single_instance.rs @@ -329,10 +329,15 @@ mod tests { #[test] fn a_stale_endpoint_file_is_ignored_and_replaced() { let (path, dir, file) = folder("stale"); - // No listener on the recorded port any more. - let port = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap().local_addr().unwrap().port(); + // The recorded app is gone: whatever holds the port closes without a greeting. (A freed + // port can be taken by another test's listener meanwhile, which would then accept this + // connection in place of its own client's.) + let gone = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap(); + let port = gone.local_addr().unwrap().port(); write_endpoint(&path, &json!({ "port": port, "token": "t", "hello": "h" })).unwrap(); + let closed = std::thread::spawn(move || drop(gone.accept())); assert!(forward(&path, std::slice::from_ref(&file)).is_err()); + closed.join().unwrap(); // A listener that doesn't know the greeting gets neither the token nor the paths. let impostor = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap(); let port = impostor.local_addr().unwrap().port();