From 2e7930fe58cdf29671ea71a066ebc80b5006b97d Mon Sep 17 00:00:00 2001 From: Amey Pawar <138877912+ameyypawar@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:30:24 +0530 Subject: [PATCH] net: accept ConnectionReset in shutdown_after_tcp_reset test (#8196) The test asserts shutdown() returns Ok(()) after the peer resets the connection (linger = 0). This holds on Linux and macOS, but on FreeBSD the kernel can finish processing the RST before shutdown() runs, so it returns ConnectionReset and the test fails intermittently -- the oneshot only synchronizes the application-level drop, not the kernel's RST processing. Accept Ok(()) or ConnectionReset for the post-reset shutdown, since both are valid for a connection the peer has already reset. --- tokio/tests/tcp_shutdown.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tokio/tests/tcp_shutdown.rs b/tokio/tests/tcp_shutdown.rs index aaac41a93..697512cc1 100644 --- a/tokio/tests/tcp_shutdown.rs +++ b/tokio/tests/tcp_shutdown.rs @@ -44,7 +44,16 @@ async fn shutdown_after_tcp_reset() { connected_tx.send(()).unwrap(); dropped_rx.await.unwrap(); - assert_ok!(AsyncWriteExt::shutdown(&mut stream).await); + + // After the peer's RST (linger = 0), `shutdown` returns `Ok(())` on most + // platforms, but FreeBSD can surface the reset as `ConnectionReset` when + // the kernel processed it before `shutdown` ran. Both are valid for an + // already-reset connection. + match AsyncWriteExt::shutdown(&mut stream).await { + Ok(()) => {} + Err(e) if e.kind() == io::ErrorKind::ConnectionReset => {} + Err(e) => panic!("unexpected error after reset: {e:?}"), + } }); let (stream, _) = assert_ok!(srv.accept().await);