Skip to content

How to send error trailers for grpc server streams #5989

@cwanda

Description

@cwanda

I want to send some trailers for grpc server streams when an error occurs mid-stream after status 200 and some data has been proxied to the client.

I do the following in the grpc server function

if err != nil {
    grpc.SetTrailer(out.Context(), metadata.Pairs("grpc-status", "13"))
    grpc.SetTrailer(out.Context(), metadata.Pairs("stream-error", "true"))
    return err
}

I do not see trailers returned in the http response ( The request has header "TE: trailers" set). I see that FowardResponseMessage () adds trailers for unary grpc, but I do not see that ForwardResponseStream() for streaming rpc adds trailers.

How do we configure grpc-gateway so grpc servers streams error trailers are sent? I considered using: WithStreamErrorHandler to customize a handler but the handler which gets called in handleForwardResponseStreamError() does not have access to the response writer and handleForwardReponseStreamError() doesn't add trailers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions