Description
I have an rpc Test(TestRequest) returns (stream TestMessage)
with an implementation that just returns an error immediately.
Then the client does this:
stream, err := testClient.Test(ctx, &TestRequest{})
if err != nil {...} // don't expect an error here
header, err := stream.Header()
// but this waited for headers... the error headers were received... where did they go?
if err != nil {...}
What is flummoxing me is that most of the time, but not always, stream.Header()
returns nil, nil
. Occasionally, running in a debugger, it returns the error. A calls to stream.Recv()
returns the error reliably, but IDK if there is an error or not, and could end up blocking indefinitely waiting for it, which isn’t good because I have an upstream waiting to know the stream was setup successfully.
What I noticed is that if there was an error, I get nil
headers instead of content-type: ...
. Can I reliably use this as a signal to invoke Recv()
and get the underlying error?
Why can't Header()
return the error? Inspection in the debugger shows that it reads the error code and message headers out of the frame, but short-circuits because the stream has terminated and internal assigns noHeaders
. I just want access to the state that is buried in there (there was an error) without having to resort to trying to recv with a timeout.