server: public ConnectionInfo; Server::serve_connection returning ConnectionClosed - #306
Merged
Merged
Conversation
… `ConnectionClosed` The private `PeerInfo` becomes the public `#[non_exhaustive]` `ConnectionInfo` (`new`, `with_peer_addr`, `with_peer_certs`, `peer_addr() -> Option<SocketAddr>`, `peer_certs()`, `extensions()`, `extensions_mut()`): what is known about a connection before its first request, including connection-scoped extensions that are cloned into every request. `PeerAddr` / `PeerCerts` on requests are always set from its typed fields, never from its extensions. `Server::serve_connection(io, info, shutdown)` serves one stream the caller accepted with the server's service and every connection setting configured on it, on whichever runtime polls it, and resolves to `ConnectionClosed` whose `reason()` names how it ended (`Closed`, `Shutdown`, `MaxAge`, `Idle`, `MaxRequests`, `Error`) — the states the connection lifecycle already distinguished. The built-in loop is unchanged apart from constructing `ConnectionInfo`. Tests: built-ins are authoritative over inserted extensions (and a forged `PeerCerts` never reaches requests); a hand-written loop over `Server::serve_connection` carries extensions and `PeerAddr`, is retired by max age, and reports `MaxAge` / `Closed`. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BgcfmMV1ECyzhbqGvUV1a7 Signed-off-by: Ryan Brewster <rpb@anthropic.com>
A connection told to shut down or retire before its peer sent a byte reported `CloseReason::Error`: hyper-util cancels protocol detection with an `Interrupted` error in that state, and any error overrode the reason. Once graceful shutdown has been issued, the shutdown or retirement reason now stands; `Error` is reserved for errors while serving. The `ConnectionInfo` docs also claimed a request never reports a peer the transport did not see; under `Server::serve_connection` the caller records the peer, so they now say so. Signed-off-by: Iain McGinniss <309153+iainmcgin@users.noreply.github.com>
iainmcgin
marked this pull request as ready for review
September 18, 2026 05:35
iainmcgin
approved these changes
Sep 18, 2026
iainmcgin
left a comment
Collaborator
There was a problem hiding this comment.
[claude code] Approving under the maintainers' agreement to review and merge each other's PRs. The added fix commits went through code, API, doc and deslop review; CI, server conformance and the MSRV check pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this, owning the accept step meant raw hyper, which drops every timeout, retirement and drain guarantee. After:
#[non_exhaustive] ConnectionInfo, formerly the privatePeerInfo, also at the crate root.PeerAddr/PeerCertson requests always come from its peer fields, never from the extensions.Server::serve_connection(&self, io, info, shutdown) -> impl Future<Output = ConnectionClosed> + Send + 'staticserves one already-accepted stream with the server's service and connection settings, on whichever runtime polls the future.Server::with_tlsdoes not apply here: the caller completes any TLS handshake first.ConnectionClosed::reason() -> CloseReason(#[non_exhaustive]). Once shutdown or a retirement trigger tells a connection to wind down, that reason is final: a peer that errors mid-drain, or that sent nothing before shutdown, reports the wind-down reason, notError.First of four stacked PRs: #306 → #307 → #308 → #304. Part of #191 and #49.