-
Notifications
You must be signed in to change notification settings - Fork 821
Description
Scenario: the server (native in this case) deliberately faults with an RpcException including some trailers in the middle of a server-streaming operation, and that trailer has also been added to the server context, i.e.
var faultTrailers = new Metadata();
faultTrailers.Add("sum", sum);
// **and** importantly
serverContext.ResponseTrailers.Add("sum", sum);
throw new RpcException(new Status(StatusCode.Internal, "oops"), faultTrailers);Expectation
as observed with the native Google client:
The client-side call await streamReader.MoveNext(cancellationToken) will surface an RpcException with the correct StatusCode, Detail and Trailers i.e. one of "sum", sum
Actual
as observed with Grpc-Dotnet
The client-side call await streamReader.MoveNext(cancellationToken) surfaces an RpcException with the correct StatusCode, Detail - but:
- sometimes the
Trailerscollection is empty - sometimes the
Trailerscollection has it twice, i.e."sum", "10,10"
I haven't figured out the rules for when it is empty and when it is duplicated; when I run just the one test, it tends to be empty; when I run a bunch of tests it tends to be duplicated. Possibly a thread race condition.
Repro
See the ServerStreaming(true) test case here - comparing NativeStreamTests to ManagedStreamTests.
A good place to put a breakpoint is in Reshape.cs, ServerStreamingAsyncImpl, on the line:
metadata?.SetTrailers(fault);(which is where the exception is surfaced)
Note that this is the exact same (native) server in both tests, so presumably this is a client bug.
Note: I have added IsManagedClient that changes the test's expectation to reflect what I am observing (so my tests acknowledge reality for now)