Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketException at client when server throws an exception with a long message #2455

Closed
bhaeussermann opened this issue Jun 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@bhaeussermann
Copy link

What version of gRPC and what language are you using?

  • Google.Protobuf 3.26.1
  • Grpc.Net.Client 2.62.0
  • Grpc.Tools 2.63.0

Language: C#

What operating system (Linux, Windows,...) and version?

Windows 11 Enterprise (10.0.22631 Build 22631)

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.NET 8.0.204

What did you do?

I followed the steps in the Microsoft tutorial for creating a .NET gRPC server and client. I modified the service operation to throw an exception with a long message as follows:

public class GreeterService : Greeter.GreeterBase
{
    public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
    {
        return Task.FromException<HelloReply>(new Exception(string.Join("", Enumerable.Repeat("soi-", 4100))));
    }
}

I have set MaxSendMessageSize to 10 MB on the server (MaxSendMessageSize = 10_485_760) and also set MaxReceiveMessageSize to 10 MB on the client. This is much larger than the length of the exception message.

If I make the operation return a long response message as in Task.FromResult(new HelloReply { Message = string.Join("", Enumerable.Repeat("soi-", 40000)) }) this works fine. This shows that the exception message isn't exceeding the maximum allowed message size.

What did you expect to see?

The following exception at the client:

Grpc.Core.RpcException: 'Status(StatusCode="Unknown", Detail="Exception was thrown by handler. Exception: soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-soi-...

What did you see instead?

The following exception at the client:

Grpc.Core.RpcException: 'Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError) HttpProtocolException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError)", DebugException="System.Net.Http.HttpRequestException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError)")'
@JamesNK
Copy link
Member

JamesNK commented Jun 5, 2024

There is a maximum limit on response header size. When it is exceeded the request fails with a protocol error, which is what the client sees.

@bhaeussermann
Copy link
Author

@JamesNK Does this mean that the exception message gets encoded into the response header as opposed to the response body?

@JamesNK
Copy link
Member

JamesNK commented Jun 5, 2024

Yes. It's Status-Message in the specific: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses

@bhaeussermann
Copy link
Author

@JamesNK Thanks. In that case fixing the issue is probably not viable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants