grpc/grpc-dotnet

Error reading next message. HttpProtocolException: The HTTP/2 server reset the stream

WeihanLi opened this issue · 1 comments

Get an error as follows when I try to read the stream message from the server response:

Call failed with gRPC error status. Status code: 'Internal', Message: 'Error reading next message. HttpProtocolException: The HTTP/2 server reset the stream. HTTP/2 error code 'INTERNAL_ERROR' (0x2). (HttpProtocolError)'.
      System.Net.Http.HttpProtocolException: The HTTP/2 server reset the stream. HTTP/2 error code 'INTERNAL_ERROR' (0x2). (HttpProtocolError)
         at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException)
         at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState()
         at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span`1 buffer, Boolean partOfSyncRead)
         at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory`1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken)
         at Grpc.Net.Client.Internal.StreamExtensions.ReadMessageAsync[TResponse](Stream responseStream, GrpcCall call, Func`2 deserializer, String grpcEncoding, Boolean singleMessage, CancellationToken cancellationToken)  
         at Grpc.Net.Client.Internal.GrpcCall`2.ReadMessageAsync(Stream responseStream, String grpcEncoding, Boolean singleMessage, CancellationToken cancellationToken)
         at Grpc.Net.Client.Internal.HttpContentClientStreamReader`2.MoveNextCore(CancellationToken cancellationToken)

sample code snippets

var handleResponseTask = Task.Run(async () =>
{
    try
    {
        await foreach (var message in call.ResponseStream.ReadAllAsync(_cacheLifetime.OnStopped))
        {
            await HandleResponse(message).ConfigureAwait(false);
        }

        async Task HandleResponse(InvocationResponseMessage message) {}
    }
    catch (Exception e)
    {
        LogReadResponseMessageError(e);
        throw;
    }
});

Found a similar error issue, not sure if it's related dotnet/runtime#72301

Should I configure something for the server?

configure the keep-alive seems helps