Skip to content

Client: server-streaming does not collect duplicated (fault+ctx) trailers during an RpcException #915

@mgravell

Description

@mgravell

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 Trailers collection is empty
  • sometimes the Trailers collection 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions