feat(grpc): add server-side Listener and Transport traits#2725
Open
sauravzg wants to merge 2 commits into
Open
feat(grpc): add server-side Listener and Transport traits#2725sauravzg wants to merge 2 commits into
sauravzg wants to merge 2 commits into
Conversation
Mirror the ChannelCredentials dyn-compat treatment from upstream PR #2703: - Remove associated type Output<I> and generic accept<Input> - Use BoxEndpoint and #[async_trait] for object safety - Delete DynServerCredentials bridge trait (dyn_wrapper.rs) - Update LocalServerCredentials and RustlsServerCredendials impls
Server-owned connection lifecycle and graceful shutdown: - Server accepts connections from a Listener and manages their lifecycle. Each accepted Transport is bound to a handler via Transport::serve(), which returns a GracefulConnection future that the Server polls and can shut down cooperatively. - Graceful shutdown follows a pattern combining the tonic Server API with hyper's graceful shutdown guide (https://hyper.rs/guides/0.14/server/graceful-shutdown/). - ListenerAddress provides a type-safe, downcastable address for listeners, analogous to Go's net.Addr. Runtime API changes: - Runtime trait gains tcp_listener() and unix_listener() methods (doc(hidden)) that return EndpointListener (pub(crate)). - EndpointListener trait (pub(crate)) wraps accept() and local_addr() for server-side listening sockets. - Tokio implementations: TokioTcpListener, TokioUnixListener. - New address module (rt::address) with ListenerAddress trait and impls for SocketAddr and UnixListenerAddress. Breaking changes: - Server::serve() now takes &impl Listener (sealed) instead of the previous ServerListener. The old ServerListener returned a pre-assembled ServerCall with constructed streams; the new Listener yields raw Transport objects and stream construction moves into Transport::serve(). - serve_with_shutdown() is pub(crate) pending a design decision on whether the shutdown signal should be per-listener or per-server. New public API surface: - Listener trait (pub, sealed) — accept(), local_addr() - Transport trait (pub, doc(hidden), private token) — serve() - GracefulConnection trait (pub, doc(hidden), private token) — graceful_shutdown() - ListenerAddress trait (pub) — network(), as_any() - ListenerAddress impl for std::net::SocketAddr - UnixListenerAddress (pub(crate)) - InMemoryServingConnection (pub) - InMemoryListenerAddress (crate-private) - EndpointListener trait (pub(crate)) - Runtime::tcp_listener(), Runtime::unix_listener() (doc(hidden))
78b7f20 to
1ff57ef
Compare
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.
Server-owned connection lifecycle and graceful shutdown:
Server accepts connections from a Listener and manages their lifecycle. Each accepted Transport is bound to a handler via Transport::serve(), which returns a GracefulConnection future that the Server polls and can shut down cooperatively.
Graceful shutdown follows a pattern combining the tonic Server API with hyper's graceful shutdown guide (https://hyper.rs/guides/0.14/server/graceful-shutdown/).
ListenerAddress provides a type-safe, downcastable address for listeners, analogous to Go's net.Addr.
Runtime API changes:
Breaking changes:
Server::serve() now takes &impl Listener (sealed) instead of the previous ServerListener. The old ServerListener returned a pre-assembled ServerCall with constructed streams; the new Listener yields raw Transport objects and stream construction moves into Transport::serve().
serve_with_shutdown() is pub(crate) pending a design decision on whether the shutdown signal should be per-listener or per-server.
New public API surface:
Open Questions:
local_addrsmay need to be updated to be errorable(contrary to our previous discussion), tonic's API is errorable and we currently do an expect.shutdownper listener vsshutdownon server