Repository navigation
Add address-agnostic Control for multiple listeners - #203
Merged
Merged
Conversation
Split the handle's shared state from its address latch. `Control` is not tied to an address type, so one TCP and one Unix server can share shutdown and connection counting while each `Handle` keeps its own `listening()`. `Handle::with_control` builds a per-listener handle on top of a `Control`. Also adds a multiple_listeners example that serves one app over TCP and a Unix socket and drains both on shutdown.
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.
Adds
Control, an address-agnostic handle that shares shutdown and connection counting across servers listening on different address types, and amultiple_listenersexample. This closes #66.Why this closes the issue
The issue asks for one app on an arbitrary list of TCP and Unix sockets, with TLS on TCP and listeners inherited from systemd socket activation. Every part of that is now supported:
from_tcpandfrom_unix(plusfrom_tcp_rustlsandfrom_unix_rustls) acceptstdlisteners, solistenfd::ListenFdoutput can be passed straight in.Clone; clone it per server.Serverper listener, each with its own acceptor, so TCP and Unix, TLS or plain, live in one process.Controlis new here:Handle::with_controlattaches each server to it, and onegraceful_shutdownorshutdowndrains all of them whileconnection_countsums their connections.Handle<A>, solistening()still reports that server's address instead of racing with other listeners.examples/multiple_listeners.rsis the full program: one router over TCP and a Unix socket, drained together on Ctrl-C, with a failing listener shutting the rest down.How the earlier changes got here
Servergeneric over streams and support Unix sockets #167 (0.8.0) madeServergeneric over its connections and added Unix sockets,from_unix,from_unix_rustls, and theAddress/AddrListenertraits. Before it the crate could only listen on TCP, so mixed listeners were not even representable.TlsInfoandLocalAddrAcceptor. The 2023 discussion on this issue objected that axum'sConnectInfoforced hyper'sAddrStreamtype; per-connection TLS details, client certificates and the local address are now available to handlers through extensions, andConnectInfo<SocketAddr>still works per TCP server because every server passes its own address as the make-service target.first_request_timeout,accept_error_handler, TCP socket options) that fit the composition model without changes.Handle<A>,Server::handleandlistening()are unchanged.Why not a single
Serverwith many listenersA
Serveris generic over oneAddress, that address's stream, its acceptor, and the service the acceptor produces (TLS wraps the service inTlsService). Putting TCP and Unix in one server would require boxed streams, boxed services and boxed accept futures, weakening the typedAccepttrait and the per-listener TLS configuration. One server per listener keeps typed acceptors, per-listener TLS and socket options, timeouts, andConnectInfo, and composes with tokio.ConnectInforemains TCP-only, because axum has noConnectedimplementation for Unix addresses. Per-server settings such asfirst_request_timeoutandaccept_error_handlerare configured on each server.