I have asp.net core 3.1 Grpc Server and asp.net core 3.1 Grpc client application. Intermittently I see the below error happening :
Status(StatusCode=Internal, Detail="Error starting gRPC call. HttpRequestException: Connection reset by peer SocketException: Connection reset by peer")
Here goes the Grpc client code:
public static async Task < TResponse > CallService < TResponse > (string urlGrpc, Func < GrpcChannel, Task < TResponse >> func) {
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
var channel = GrpcChannel.ForAddress(urlGrpc);
// var channel = GrpcChannel.ForAddress("http://localhost:32769");
/*
using var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
*/
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, channel.Target);
try {
return await func(channel);
} catch(RpcException e) {
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
return
default;
} finally {
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
}
}
I have been using Azure Dev Spaces for debugging in my local environment.
Can anyone help me here by providing their guidance to fix this issue.