Skip to content

Commit 0adcd20

Browse files
alexchenaiRalith
authored andcommitted
docs: clarify that Event::ConnectionLost is not emitted on local close
Clarify in the documentation for `Event::ConnectionLost`, `is_closed()`, and `is_handshaking()` that the `ConnectionLost` event is only emitted when the connection is closed by the peer or due to an error/timeout. When the local application calls `Connection::close()`, no `ConnectionLost` event is emitted; instead, pending operations fail with `ConnectionError::LocallyClosed`. Fixes #1495
1 parent f0905db commit 0adcd20

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • quinn-proto/src/connection

quinn-proto/src/connection/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,9 @@ impl Connection {
13061306
/// Whether the connection is in the process of being established
13071307
///
13081308
/// If this returns `false`, the connection may be either established or closed, signaled by the
1309-
/// emission of a `Connected` or `ConnectionLost` message respectively.
1309+
/// emission of a [`Connected`](Event::Connected) or [`ConnectionLost`](Event::ConnectionLost)
1310+
/// event respectively. Note that locally-initiated closes via [`close()`](Self::close) do not
1311+
/// emit a `ConnectionLost` event.
13101312
pub fn is_handshaking(&self) -> bool {
13111313
self.state.is_handshake()
13121314
}
@@ -1317,7 +1319,10 @@ impl Connection {
13171319
/// either peer application intentionally closes it, or when either transport layer detects an
13181320
/// error such as a time-out or certificate validation failure.
13191321
///
1320-
/// A `ConnectionLost` event is emitted with details when the connection becomes closed.
1322+
/// A [`ConnectionLost`](Event::ConnectionLost) event is emitted with details when the
1323+
/// connection is closed by the peer or due to an error. When the local application closes
1324+
/// the connection via [`close()`](Self::close), no `ConnectionLost` event is emitted;
1325+
/// instead, pending operations fail with [`ConnectionError::LocallyClosed`].
13211326
pub fn is_closed(&self) -> bool {
13221327
self.state.is_closed()
13231328
}
@@ -4034,7 +4039,10 @@ pub enum Event {
40344039
HandshakeConfirmed,
40354040
/// The connection was lost
40364041
///
4037-
/// Emitted if the peer closes the connection or an error is encountered.
4042+
/// Emitted when the connection is closed due to an error, a timeout, or the peer closing it.
4043+
/// This is **not** emitted when the local application closes the connection via
4044+
/// [`Connection::close()`](crate::Connection::close). In that case, pending operations will
4045+
/// fail with [`ConnectionError::LocallyClosed`].
40384046
ConnectionLost {
40394047
/// Reason that the connection was closed
40404048
reason: ConnectionError,

0 commit comments

Comments
 (0)