You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
If the headerError variable is not undefined, and the request.body evaluates to a false value (i.e. there is no body); or
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).
I have experimented with and found two potential solution candidates for this bug.
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.
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).
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:headerError
variable is notundefined
, and therequest.body
evaluates to a false value (i.e. there is no body); orheaderError
variable is notundefined
, and thetrailer
variable isundefined
. 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, thetrailer
variable will be set to an instance ofHeaders
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 code2
, completely disregarding the value ofheaderError
.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):
1.6.1
(however, the problematic code is also present in thev2
branch).[email protected]
v22.12.0
Potential Solutions
I have experimented with and found two potential solution candidates for this bug.
message
variable isundefined
, throw theheaderError
if present. This change will bring this code path inline with how themissing trailer
error is thrown a few lines above.connect-es/packages/connect-web/src/grpc-web-transport.ts
Line 226 in af47285
trailer
variable isundefined
could be updated to also check if thetrailer
variable has a length equal to zero (i.e. no entries in theHeaders
instance).connect-es/packages/connect-web/src/grpc-web-transport.ts
Line 216 in af47285
The text was updated successfully, but these errors were encountered: