Skip to content

Commit bc2e70a

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 bc2e70a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

noq/src/connection.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,14 @@ impl Drop for ConnectionRef {
12331233
// be constructed for the newly opened stream.
12341234
conn.implicit_close(&self.shared);
12351235
}
1236+
1237+
// We also flush any pending packets, e.g. the CONNECTION_CLOSE, if we're able to do so
1238+
// synchronously. This is best-effort; we won't wait for them to be acked, but we have a
1239+
// decent chance of notifying the peer in the case that we're currently shutting down
1240+
// ungracefully.
1241+
let waker = std::task::Waker::noop();
1242+
let mut cx = std::task::Context::from_waker(waker);
1243+
let _ = conn.drive_transmit(&mut cx);
12361244
}
12371245
}
12381246

@@ -1709,6 +1717,7 @@ impl State {
17091717
fn close(&mut self, error_code: VarInt, reason: Bytes, shared: &Shared) {
17101718
self.inner.close(self.runtime.now(), error_code, reason);
17111719
self.terminate(ConnectionError::LocallyClosed, shared);
1720+
17121721
self.wake();
17131722
}
17141723

0 commit comments

Comments
 (0)