Julien Martin
Julien Martin

Reputation: 421

RpcException on ConfigurationLoadCredential .Net 7

My client gRPC send multiple requests to my gRPC Server, but first request crash with RpcException :

Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: An internal error has occurred. ConfigurationLoadCredential failed: Unknown (0x80090331) (localhost:5057) QuicException: An internal error has occurred. ConfigurationLoadCredential failed: Unknown (0x80090331)", DebugException="System.Net.Http.HttpRequestException: An internal error has occurred. ConfigurationLoadCredential failed: Unknown (0x80090331) (localhost:5057)")

Next requests don't crash. Client application and server application running on Windows Server 2022 and are installed as Windows Service.

On Event viewer errors are logged :

A fatal error occurred while creating a TLS client credential. The internal error state is 10013.

On Windows 10 and Windows Server 2019, no request crashes... It's very strange.

gRPC client (I don't use certificate for test) :

        services.AddGrpcClient<ShipmentProtoService.ShipmentProtoServiceClient>(o =>
        {
            o.Address = new Uri("my uri"));
        })
        .ConfigureChannel(op =>
        {
            var httpClientHandler = new HttpClientHandler();
            httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
           
            op.HttpHandler = httpClientHandler;
        });

gRPC Server :

        services.AddGrpc(opt =>
        {
            opt.EnableDetailedErrors = true;
            opt.Interceptors.Add<LoggerInterceptor>();
            opt.Interceptors.Add<ExceptionInterceptor>();
        });

Upvotes: 1

Views: 194

Answers (1)

Julien Martin
Julien Martin

Reputation: 421

I tested sending hundreds of gRPC requests to a Windows Server 2019 and didn't encounter any errors. When I performed the same test on a Windows Server 2022, I received the error:

'An unrecoverable error occurred when creating a TLS client credential. The internal error state is 10013.'

The protocols used on both servers are the same: TLS 1.1, TLS 1.2, and TLS 1.3. While waiting to understand the issue, I used the Polly Library to retry sending the request if there is an error.

var policy = Polly.Policy.Handle<Exception>()
        .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
        {
            _logger.LogWarning(ex, "Could not get data from gRPC protocol after {Timeout}s ({ExceptionMessage})", $"{time.TotalSeconds:n1}", ex.Message);
        });

        var response= await policy.ExecuteAndCaptureAsync(async () =>
        {
            return await _myService.GetDataAsync(new Request
            {
                IdCom = idcom,
                Value = "test"
            });
        });

Upvotes: 0

Related Questions