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
if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, defaultTimeout)
defer cancel()
}
return handler(ctx, req)