#4394·gofr

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 ERROR

Root cause

  • pkg/gofr/grpc/log.go uses status.FromError(err) in logStreamRPC (line 220) and logRPC (line 242). For errors that aren't gRPC status errors, that returns codes.Unknown.
  • grpc-go converts those errors with status.FromContextError before writing the status to the client, in processUnaryRPC and processStreamingRPC in server.go.
  • isServerError (line 303) has the same problem, so a cancellation is classified as a server error and logged with Errorf.

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:

go
func grpcCode(err error) codes.Code {
	if s, ok := status.FromError(err); ok {
		return s.Code()
	}

	return status.FromContextError(err).Code()
}