grpc-dotnet icon indicating copy to clipboard operation
grpc-dotnet copied to clipboard

Unable to diagnose root cause of `StatusCode.Internal` faults

Open jimgolfgti opened this issue 3 years ago • 3 comments

In the course of trying to diagnose why we are seeing occasional StatusCode.DeadlineExceeded whilst performing unary calls we configured logging of the RetryCall.EvaluateRetry result, see https://github.com/grpc/grpc-dotnet/blob/6bf44820a2ef6af5845830728cd4b3d1a8053ed4/src/Grpc.Net.Client/Internal/Retry/RetryCall.cs#L201

When evaluating the retry when the Status.StatusCode is StatusCode.Internal we are unable to see the detailed reason, it is lost once the method returns due to the status being overwritten by the DeadlineExceeded evaluation result, https://github.com/grpc/grpc-dotnet/blob/6bf44820a2ef6af5845830728cd4b3d1a8053ed4/src/Grpc.Net.Client/Internal/Retry/RetryCall.cs#L229-L233

Is it possible to change the log message to pass the entire Status object? Looking at the implementation it already serialises all the fields in its ToString override, https://github.com/grpc/grpc-dotnet/blob/6bf44820a2ef6af5845830728cd4b3d1a8053ed4/src/Grpc.Core.Api/Status.cs#L87-L95

jimgolfgti avatar Apr 27 '23 10:04 jimgolfgti

The error details of the previous call aren't in that particular log, but are they available in other log messages? It seems redundant to repeat exception information in multiple places.

If the error details are in other logs, why do you also want them here?

JamesNK avatar Apr 27 '23 13:04 JamesNK

Tracing back through the code prior to the retry evaluation from what I could see, perhaps you know where else we could capture the fault, the status was built inside GrpcCall.ValidateHeaders. AFAIK logging this information here is not redundant.

I cannot see that the detail is logged anywhere else between construction and retry evaluation. As I mentioned, if the deadline has passed then the failed call is lost and replaced by a new status call with a constant status. If the deadline has not passed then the status is also lost with the next call attempt.

jimgolfgti avatar Apr 27 '23 15:04 jimgolfgti

This is what I see when I run the Unary_ExceedRetryAttempts_Failure test and look at the logs:

0.036s Grpc.Net.Client.Internal.RetryCall - Trace: Starting retry worker.
0.037s Grpc.Net.Client.Internal.RetryCall - Debug: Starting attempt 1.
0.048s Grpc.Net.Client.Internal.GrpcCall - Debug: Starting gRPC call. Method type: 'Unary', URI: 'http://127.0.0.1:50050/DynamicService/d866aca4-4ea5-46e7-923e-34d0cddba63d'.
0.088s Grpc.Net.Client.Internal.GrpcCall - Trace: Serialized 'Streaming.DataMessage' to 0 byte message.
0.091s Grpc.Net.Client.Internal.RetryCall - Trace: Message with 5 bytes added to the buffer. There are 5 bytes buffered for this call.
0.092s Grpc.Net.Client.Internal.GrpcCall - Debug: Sending message.
0.093s Grpc.Net.Client.Internal.GrpcCall - Trace: Message sent.
0.155s Grpc.Net.Client.Internal.GrpcCall - Trace: Response headers received.
0.157s Grpc.Net.Client.Internal.RetryCall - Debug: Retry pushback of '5' received from the failed gRPC call.
0.157s Grpc.Net.Client.Internal.GrpcCall - Information: Call failed with gRPC error status. Status code: 'Unavailable', Message: ''.
0.157s Grpc.Net.Client.Internal.GrpcCall - Debug: Finished gRPC call.
0.159s Grpc.Net.Client.Internal.RetryCall - Debug: Evaluated retry for failed gRPC call. Status code: 'Unavailable', Attempt: 1, Retry: True
0.160s Grpc.Net.Client.Internal.RetryCall - Trace: Starting retry delay of 00:00:00.0050000.
0.166s Grpc.Net.Client.Internal.RetryCall - Debug: Starting attempt 2.

The failed response that caused the retry, including the Status.Detail value, is available here:

0.157s Grpc.Net.Client.Internal.GrpcCall - Information: Call failed with gRPC error status. Status code: 'Unavailable', Message: ''.

The status detail could be included with the evaluated retry message, but it seems unnecessary.

JamesNK avatar Apr 28 '23 03:04 JamesNK