From 9c78d4b17b2a6f977a3d085f29bd70e336431d9b Mon Sep 17 00:00:00 2001 From: Colin Marc Date: Wed, 29 Apr 2026 17:41:26 +0200 Subject: [PATCH] fix: do a best-effort transmit on connection close If we're shutting down ungracefully, we can make a best-effort attempt to write the CONNECTION_CLOSE to the socket and notify the peer. If we're in the middle of graceful shutdown, it doesn't hurt, either. --- noq/src/connection.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/noq/src/connection.rs b/noq/src/connection.rs index 4238a79ea..ebc7afd0c 100644 --- a/noq/src/connection.rs +++ b/noq/src/connection.rs @@ -1233,6 +1233,14 @@ impl Drop for ConnectionRef { // be constructed for the newly opened stream. conn.implicit_close(&self.shared); } + + // We also flush any pending packets, e.g. the CONNECTION_CLOSE, if we're able to do so + // synchronously. This is best-effort; we won't wait for them to be acked, but we have a + // decent chance of notifying the peer in the case that we're currently shutting down + // ungracefully. + let waker = std::task::Waker::noop(); + let mut cx = std::task::Context::from_waker(waker); + let _ = conn.drive_transmit(&mut cx); } }