grpc/grpc-dotnet

gRPC Client Never Receives Response Headers when Using Grpc.Core.Channel

M-Sherif opened this issue · 2 comments

What version of gRPC and what language are you using?

GRPC 2.32.0 and Grpc.Net.Client 2.31.0 NuGet package with C#.

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

Windows 10 20H2.

What runtime / compiler are you using (e.g. python version or version of gcc)

.Net Core 3.1.

What did you do?

On the gRPC server, I return response header containing server info once a request starts. On the client side, I block until I receive this information before sending the request body. This scenario works properly without issues when I use GrpcChannel.ForAddress for creating the channel. Once I switch to creating the Grpc.Core.Channel on my own, the client never receives the response headers sent from the server. Changing how the channel is created is the only code change needed to reproduce the issue and it happens consistently.

Channel creation that works:
var channel = GrpcChannel.ForAddress("http://localhost:5000");

Channel creation code that doesn't work:
var channel = new Channel(uri.DnsSafeHost, uri.Port, ChannelCredentials.Insecure);

Server code snippt:

 public override async Task<FResult> DoWork(IAsyncStreamReader<FRequest> requestStream, ServerCallContext context)
        {
                    var headers = new Metadata() { new Metadata.Entry("serverinfo", this.serverInfo) };
            await context.WriteResponseHeadersAsync(headers).ConfigureAwait(false);
            ...
         }

Client code snippet:

         protected override Func<Task> OnNextAsync(Segment payload)
         {         
         ...
         
         var call = client.DoWork(this.metadata, cancellationToken: this.grpcCancellationTokenSource.Token);
         var headers = await call.ResponseHeadersAsync.ConfigureAwait(false);
         
         ...
         }

The following line that reads the response headers on the client side never returns in the faulty case, although by debugging I can verify that the server executed await context.WriteResponseHeadersAsync.
var headers = await grpc.ResponseHeadersAsync.ConfigureAwait(false);

What did you expect to see?

Expected the response headers to be received by the client.

What did you see instead?

The client awaits but never receives the response header.

Anything else we should know about your project / environment?

Are you using a grpc-dotnet server (ASP.NET core based) or Grpc.Core based server?
Also, is this problem Windows specific or you can also reproduce on linux?

Have you tried extra logging by enabling GRPC_VERBOSITY and GRPC_TRACE?
https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md It could tell you whether the header was actually received on the client side (and or sent out on the wire on the server side).

Also the behavior you're describing is quite odd, since we have unit tests that should cover this - it would be best if you could provide a ready-to-run reproduction (ideally as a github repository) that has both the client and server and reproduces the problem you described.

Closing as there was no followup from the user.