Skip to content

gRPC Server: Interceptor Not Running

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about grpc server: interceptor not running. We cover key concepts, practical examples, and best practices.

gRPC server interceptors -- Register server-side interceptors in grpc.NewServer options to add logging, auth, and recovery.

The Problem

Interceptors must be passed as grpc.ServerOption. Adding them after server creation has no effect.

Wrong

server := grpc.NewServer()
pb.RegisterUserServer(server, &userServer{})
server.Serve(listener)

Output:

// No interceptors. Errors and panics go unhandled.
server := grpc.NewServer(
    grpc.ChainUnaryInterceptor(
        logging.UnaryServerInterceptor(logger),
        auth.UnaryServerInterceptor(validator),
        recovery.UnaryServerInterceptor(),
    ),
)
pb.RegisterUserServer(server, &userServer{})

Output:

// Requests logged, authenticated, panics recovered.

Prevention

  • Use ChainUnaryInterceptor to compose multiple interceptors
  • StreamInterceptor for streaming RPCs
  • Order: first registered runs first on request
  • Common: Recovery -> Logging -> Auth -> Rate Limit
  • Return status.Error for proper gRPC error codes

Common Mistakes with grpc server interceptor

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

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 is the difference between Unary and Stream interceptor?**

Unary for single request-response. Stream for streaming RPCs.

Can I add interceptors after server is created?

No. Must be in NewServer options.

How to pass data between interceptors?

Use context.WithValue or grpc.SetHeader.


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