gRPC deadline

A gRPC deadline specifies the latest time by which an RPC should complete, allowing cancellation to propagate when the operation takes too long. In this course, a server interceptor applies a default timeout only when the incoming context has no deadline and preserves an earlier deadline supplied by the client.

Minimal example

go
if _, ok := ctx.Deadline(); !ok {
    var cancel context.CancelFunc
    ctx, cancel = context.WithTimeout(ctx, defaultTimeout)
    defer cancel()
}
return handler(ctx, req)

Learn this concept

Lesson 7.15 · Release checks and gRPC recovery

Used in exercises

Exercise 7.17 · gRPC resilience interceptors