Skip to content

gRPC Deadline: Context Timeout Not Passed

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about grpc deadline: context timeout not passed. We cover key concepts, practical examples, and best practices.

gRPC deadline propagation -- Set context deadlines on gRPC client calls and enforce them on the server.

The Problem

gRPC client calls without deadline wait indefinitely. Servers should respect the incoming deadline to avoid wasted work.

Wrong

resp, err := client.GetUser(context.Background(), req)

Output:

// Hangs if server is slow or unresponsive.
// Client:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
resp, err := client.GetUser(ctx, req)
// Server checks deadline:
func (s *server) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.User, error) {
    deadline, ok := ctx.Deadline()
    if !ok {
        return nil, status.Error(codes.Internal, "deadline required")
    }
    if time.Until(deadline) < time.Second {
        return nil, status.Error(codes.DeadlineExceeded, "too late")
    }
    // Do work...
}

Output:

// Client fails fast after 5s. Server rejects calls with insufficient time.

Prevention

  • Always set deadline on gRPC client calls
  • Servers can check ctx.Deadline() and ctx.Err()
  • Deadline propagates from client to server automatically
  • Set generous deadline (10-30s) for most RPCs
  • Use shorter deadline for real-time RPCs

Common Mistakes with grpc deadline

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world GO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**What happens when server exceeds deadline?**

Client gets DeadlineExceeded error. Server should continue? No, check ctx.Done().

Can I set default server deadline?

Yes. Use grpc.TimeoutServerInterceptor from grpc-ecosystem.

Does deadline propagate across service calls?

Yes. Context with deadline is forwarded to downstream gRPC calls.


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tutorials help Go developers build production-ready software used by millions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro