0Pricing
C# Academy · Lesson

Deadlines, Cancellation & Interceptors

Apply timeouts with deadlines, propagate CancellationToken, and add cross-cutting concerns via gRPC interceptors.

Reliability in gRPC: Deadlines & Cancellation

Production gRPC services must handle two critical reliability concerns: deadlines (how long the client will wait) and cancellation (stopping work early). Together they prevent resource exhaustion and cascade failures.

Setting a Deadline on a Call

A deadline is an absolute point in time by which the call must complete. Set it with CallOptions. If exceeded, the server receives a cancellation and the client gets StatusCode.DeadlineExceeded.

var deadline = DateTime.UtcNow.AddSeconds(5);

var reply = await client.GetOrderAsync(
    new GetOrderRequest { Id = 42 },
    deadline: deadline);

// Or via CallOptions:
var options = new CallOptions(deadline: deadline);
var reply2 = await client.GetOrderAsync(
    new GetOrderRequest { Id = 42 }, options);

All lessons in this course

  1. gRPC & Protobuf Fundamentals
  2. Unary & Server Streaming RPCs
  3. Client & Bidirectional Streaming
  4. Deadlines, Cancellation & Interceptors
← Back to C# Academy