expression
Tonic: distinguish connection and request timeout policies
Connection setup and request handling need separate budgets. Endpoint timeout is a local service policy and does not insert grpc-timeout metadata. Configure Request::set_timeout separately when the remote service needs a deadline. This fixture creates configuration without connecting. Run in the accompanying Cargo project. Expected stdout (not executed): request metadata: false Common mistake: Assuming a local endpoint timeout communicates the budget to the server or covers consumption of the entire response stream.
Formal Syntax & Structure
rust syntaxrust
Endpoint::from_static(uri).connect_timeout(connect_budget).timeout(request_budget)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use std::time::Duration; use tonic::transport::Endpoint; let _endpoint = Endpoint::from_static("http://127.0.0.1:50051") .connect_timeout(Duration::from_secs(1)) .timeout(Duration::from_secs(2)); let req = tonic::Request::new(()); println!("request metadata: {}", req.metadata().get("grpc-timeout").is_some());}