Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC Web header error ignored when empty trailer frame is present #1434

Open
aborrello opened this issue Feb 25, 2025 · 0 comments
Open

gRPC Web header error ignored when empty trailer frame is present #1434

aborrello opened this issue Feb 25, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@aborrello
Copy link

Describe the bug

When using the transport created by createGrpcWebTransport(), if the upstream gRPC service returns an error, it will be ignored if the response is accompanied with an empty trailer frame. The current gRPC Web transport implementation only has two scenarios where the header error extracted from the response will be thrown:

  1. If the headerError variable is not undefined, and the request.body evaluates to a false value (i.e. there is no body); or
  2. If the headerError variable is not undefined, and the trailer variable is undefined. This logic appears to denote that if after the body has been processed, and if there are no trailers, then the header error is thrown (if present).

Focusing on these points above, if the response body only contains an empty trailer frame (i.e. uint8[128, 0, 0, 0, 0]), then the header error will never be thrown. Instead, the trailer variable will be set to an instance of Headers with no records, and proceed as if there was no error returned from the service. As a result, [unknown] missing message will be incorrectly thrown with error code 2, completely disregarding the value of headerError.

To Reproduce

This specific issue was encountered when using the Traefik Proxy GrpcWeb middleware to dynamically proxy and translate gRPC Web requests into pure gRPC requests. Their specific implementation of the protocol will always send an empty trailer frame, which does not appear to be disallowed as part of the specification. Note that while I have only experienced this issue with the Traefik Proxy, this issue can occur with any gRPC Web proxy that sends an empty trailer frame.

The issue can be reproduced by using the Traefik GrpcWeb middleware in front of any gRPC service that returns an error. If an RPC error is returned while using the connect-es client with the grpcWebTransport, the thrown error will be [unknown] missing message instead of the actual error.

Note: If necessary, I am happy to provide a gist with configuration and Docker containers to properly reproduce this issue.

Environment (please complete the following information):

  • @connectrpc/connect-web version: 1.6.1 (however, the problematic code is also present in the v2 branch).
  • Frontend framework and version: [email protected]
  • Node.js version: v22.12.0

Potential Solutions

I have experimented with and found two potential solution candidates for this bug.

  1. After the if conditional validating if the message variable is undefined, throw the headerError if present. This change will bring this code path inline with how the missing trailer error is thrown a few lines above.

if (message === undefined) {

  1. Alternatively (less preferred), the conditional validating if the trailer variable is undefined could be updated to also check if the trailer variable has a length equal to zero (i.e. no entries in the Headers instance).

if (trailer === undefined) {

@aborrello aborrello added the bug Something isn't working label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant