Skip to content

examples: add server-side timeout example#2541

Open
Sim-hu wants to merge 1 commit intohyperium:masterfrom
Sim-hu:timeout-example
Open

examples: add server-side timeout example#2541
Sim-hu wants to merge 1 commit intohyperium:masterfrom
Sim-hu:timeout-example

Conversation

@Sim-hu
Copy link

@Sim-hu Sim-hu commented Mar 8, 2026

Summary

  • Adds a timeout example with server and client binaries
  • Server uses Server::builder().timeout() to enforce a 2-second request deadline
  • Client demonstrates both fast and slow requests, plus Request::set_timeout() for client-side deadlines
  • Reuses the existing helloworld proto

Motivation

The existing cancellation example covers client-initiated cancellation but not server-enforced timeouts. Server::builder().timeout() is documented in the API but has no dedicated example. Server-side timeouts and gRPC deadline propagation are common production requirements.

Checklist

  • cargo build --bin timeout-server --bin timeout-client
  • Tested: fast request succeeds, slow request gets CANCELLED / "Timeout expired"
  • cargo clippy --bin timeout-server --bin timeout-client
  • cargo fmt --check

Add a timeout example with both server and client demonstrating:
- Server-side timeout via `Server::builder().timeout()`, which returns
  a CANCELLED status when a handler exceeds the deadline
- Client-side deadline via `Request::set_timeout()`, which sends the
  `grpc-timeout` header

The existing cancellation example covers client-initiated cancellation
but not server-enforced timeouts. This fills that gap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant