expression

gRPC: a deadline error does not prove a write failed

A state-changing operation might succeed even if its response arrives too late. Reconcile the outcome using a stable operation ID or a service-supported idempotency contract before retrying. This synthetic model records a successful write but returns an elapsed status; it is not a durable store or an idempotency implementation. Run in the accompanying Cargo project. Expected stdout (not executed): reconciled: 42 Common mistake: Retrying a non-idempotent write immediately after a timeout because the client assumes nothing happened.

Formal Syntax & Structure

rust syntaxrust
match status.code() { Code::DeadlineExceeded => ... }

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    use std::collections::BTreeMap;    let mut committed = BTreeMap::new();    committed.insert("demo-op-7", 42_u64);    let status = tonic::Status::deadline_exceeded("response budget elapsed");    if status.code() == tonic::Code::DeadlineExceeded {        println!("reconciled: {}", committed["demo-op-7"]);    }}
Rust Reference