Skip to content

Commit 79865e2

Browse files
committed
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.
1 parent ee806ab commit 79865e2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

noq/src/connection.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,14 @@ impl State {
17091709
fn close(&mut self, error_code: VarInt, reason: Bytes, shared: &Shared) {
17101710
self.inner.close(self.runtime.now(), error_code, reason);
17111711
self.terminate(ConnectionError::LocallyClosed, shared);
1712+
1713+
// If we're able to synchronously write the CONNECTION_CLOSED, it's
1714+
// advantageous to do so; we might be shutting down ungracefully, and
1715+
// this way we have a decent shot of notifying the peer.
1716+
let waker = std::task::Waker::noop();
1717+
let mut cx = std::task::Context::from_waker(waker);
1718+
let _ = self.drive_transmit(&mut cx);
1719+
17121720
self.wake();
17131721
}
17141722

0 commit comments

Comments
 (0)