Operations
Server settings, TLS, reflection, health checks, deadlines on the wire and graceful shutdown for gRPC.
ulo_grpc::Server::new(endpoint) is an HTTP/2 server on tokio. The endpoint is text, a SocketAddr or an Endpoint, and can be an inherited socket. TLS and socket activation work as they do for HTTP.
Settings
| Method | Default | Effect |
|---|---|---|
endpoint(..) | one more endpoint the same server listens on | |
tls(Tls) | none | TLS on every endpoint, ALPN h2, loaded when the server prepares |
max_inflight(Count) | 1,024 | calls in flight across the server. Over it a call gets UNAVAILABLE |
max_per_connection(Count) | none of its own | calls in flight per connection |
shed_retry_after(Duration) | 1 second | the wait a call refused over max_inflight or max_per_connection is asked to observe, sent as grpc-retry-pushback-ms in whole milliseconds rounded up |
max_concurrent_streams(Count) | hyper's | SETTINGS_MAX_CONCURRENT_STREAMS. Excess streams get REFUSED_STREAM |
handshake_timeout(Bound) | 30 seconds | how long a TLS handshake may take |
timeout_grace(Bound) | 1 second | how long error handlers may take with a passed deadline's Timeout before DEADLINE_EXCEEDED is sent |
reflection(bool) | on in debug builds | serves reflection in release builds when true |
file_descriptor_set(&'static [u8]) | none | the descriptor set reflection serves |
Count::Max(0) and Bound::After(Duration::ZERO) are refused when the server prepares. Count, Bound, Endpoint, EndpointSpec and Tls are re-exported from ulo_grpc::config.
Over a limit, a call gets UNAVAILABLE ("the server is at its in-flight limit") before an execution opens, with grpc-retry-pushback-ms set from shed_retry_after. Clients treat it as retryable. The refusal during the drain carries no pushback.
TLS
ulo_grpc::Server::new("127.0.0.1:0").reflection(false).tls(Tls::from_pem(cert.cert_pem(), cert.key_pem()))This is from crates/ulo-codegen-tests/tests/grpc_tls.rs. Tls::from_pem_files(cert, key) reads files instead. The bound address is marked secure and a plaintext client does not reach a handler. A certificate or key that does not load is a startup error that keeps its TlsError cause. The server verifies no client certificate. A client's side is ClientTls.
Reflection
grpc.reflection.v1 and v1alpha serve the descriptor set, so grpcurl can list services without the proto. Ask ulo-build to write the set, and hand it to the server:
ulo_build::configure().file_descriptor_set_path("users.bin").compile(&["proto/users.proto"], &["proto"])?;ulo_grpc::Server::new(addr).file_descriptor_set(pb::FILE_DESCRIPTOR_SET).reflection(true)include_proto! exposes the set as FILE_DESCRIPTOR_SET when the build wrote one. Reflection is on in debug builds and behind reflection(true) in release builds. With reflection on and no set, the two services describe only themselves. A set that does not decode fails startup.
Reflection lists every service and method. Scoped pre-dispatch entries whose scope matches its path run before it, so apply_for::<ApiKeyAuth>(["/*"]) refuses an anonymous listing.
Health
grpc.health.v1 answers without any setup. The server reports SERVING for every service its handlers name once it has bound, and NOT_SERVING for each of them and for the overall status "" from the start of the drain, before the GOAWAY, so a client polling health stops sending first. A service no handler names answers NOT_FOUND to Check.
To set a status per service, import GrpcHealth::module() and inject Dep<GrpcHealth>:
let health = app.handle.get::<GrpcHealth>().await?;
health.set_named(VAULT, ServingStatus::NotServing).await;From crates/ulo-codegen-tests/tests/builtins.rs. set::<S>(status) takes a tonic service type, status(name) reads a status back.
ulo-health-grpc writes the overall status "" from the application's readiness: NOT_SERVING at shutdown and whenever a health check is down, SERVING otherwise.
m.import(ulo_health::HealthModule::new());
m.import(ulo_health_grpc::HealthGrpc::new());It re-evaluates every 5 seconds, since gRPC's Check reads a stored status. HealthGrpc::new().interval(Bound) changes that. Bound::Unbounded leaves statuses changing at lifecycle transitions only. Readiness checks are covered on Health checks.
Health is never subject to a scoped pre-dispatch entry: Kubernetes' gRPC probe and load balancers call it without credentials. Watch on a name nothing has written answers NOT_FOUND and ends, where the specification streams SERVICE_UNKNOWN. This is tonic-health's behaviour. The Kubernetes probe sends Check.
Deadlines on the wire
The server parses grpc-timeout itself, as 1 to 8 digits and a unit from H, M, S, m, u or n, and turns it into the execution's deadline. A value off that grammar is answered INTERNAL, quoting up to 64 characters of the value, before any handler or error handler runs. A zero amount such as 0S is a spent budget and is answered DEADLINE_EXCEEDED with no handler run. When a positive deadline passes first, the handler is dropped, the execution is cancelled with the reason Deadline, and error handlers get the Timeout. A deadline passing while a reply stream is open ends it with DEADLINE_EXCEEDED trailers.
Messages and compression
Requests decode under tonic's 4 MiB limit, and the server has no setting for it. A request whose grpc-encoding is not identity is answered UNIMPLEMENTED with grpc-accept-encoding: identity before dispatch. Compression is unsupported.
Shutdown
On shutdown the server sends GOAWAY, and calls in flight finish within the drain window. A call that arrives after the drain begins gets UNAVAILABLE, "the server is shutting down". A call or reply stream still running when the window ends is cancelled with the reason Drain and ends UNAVAILABLE with the same phrase in its trailers. close then gives the connections up to 500 ms to finish writing before it aborts them.
Wiring the shutdown signal is covered in Deployment.
Interoperability
CI's grpc interop job serves the gRPC project's interop TestService from ulo-grpc and calls it with grpc-go's standard interop client: 16 cases over plaintext and again over TLS. The compression cases are not run. The server, the runner and the case list are in crates/ulo-grpc-interop.