gRPC logs status 2 (Unknown) when a handler returns context.Canceled or DeadlineExceeded, while the client receives 1 or 4
Author: NitinKumar004Created Sep 27, 2026Updated Oct 1, 2026
Summary
When a gRPC handler (unary or streaming) returns context.Canceled or context.DeadlineExceeded, plain or wrapped, grpc-go sends the client Canceled (1) or DeadlineExceeded (4). GoFr's gRPC log entry records statusCode: 2 (Unknown) instead.
Because the code is misread as Unknown, a client cancellation, which GoFr means to treat as a client-side error, is also logged at ERROR level.
Reproduction
A real grpc-go server (v1.83.2, as in go.mod) with GoFr's observability interceptor, and a handler that returns the error:
handler returns context.Canceled -> client receives code 1, GoFr log statusCode 2, logged at ERROR
handler returns context.DeadlineExceeded -> client receives code 4, GoFr log statusCode 2, logged at ERROR
handler returns fmt.Errorf("x: %w", DeadlineExceeded) -> client receives code 4, GoFr log statusCode 2, logged at ERRORRoot cause
pkg/gofr/grpc/log.gousesstatus.FromError(err)inlogStreamRPC(line 220) andlogRPC(line 242). For errors that aren't gRPC status errors, that returnscodes.Unknown.- grpc-go converts those errors with
status.FromContextErrorbefore writing the status to the client, inprocessUnaryRPCandprocessStreamingRPCinserver.go. isServerError(line 303) has the same problem, so a cancellation is classified as a server error and logged withErrorf.
Impact
- The logs disagree with what clients actually see.
- Timeouts and client cancellations look like Unknown server errors and add ERROR-level noise.
- Once the status code is added to the gRPC metrics (#4261 / #4349), the metrics will carry the wrong code too, and error-rate alerts will count cancellations as server errors.
Suggested fix
Add one helper that mirrors grpc-go, and use it in logRPC, logStreamRPC and isServerError:
func grpcCode(err error) codes.Code {
if s, ok := status.FromError(err); ok {
return s.Code()
}
return status.FromContextError(err).Code()
}Source: gofr-dev/gofr