Skip to content

Reject invalid gRPC responses and preserve HTTP diagnostics - #10

Merged
samuel-williams-shopify merged 13 commits into
mainfrom
fix-grpc-interoperability
Sep 24, 2026
Merged

samuel-williams-shopify merged 13 commits into
mainfrom
fix-grpc-interoperability

Conversation

@samuel-williams-shopify

@samuel-williams-shopify samuel-williams-shopify commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

An HTML error response from a server or proxy currently enters the gRPC frame decoder and produces a misleading truncated-frame error. Reject responses unless they have HTTP status 200 and a gRPC content type, raising Async::GRPC::ResponseError before decoding frames.

The client raises ResponseError.for(response). This factory builds a descriptive message and passes it with response.buffered! to initialize(message, response). Callers can inspect status and headers through error.response and read the raw body through error.response.read. Buffering closes the network body through Body#each, including when reading raises. Invalid responses are not interpreted for gRPC status; valid gRPC responses retain their existing status and trailer handling.

Validation buffers the full body before raising the error, so it waits for body completion and stores that body in memory. The compatibility adapter in socketry/async-grpc-compatible#7 applies the HTTP-to-gRPC status mapping and retains this error as the cause. For example, an HTML HTTP 503 becomes GRPC::Unavailable with the HTML accessible through error.cause.response.read.

Requests use application/grpc. Require the released protocol-grpc ~> 0.16 dependency, with dispatcher integration tests confirming server backtraces are omitted by default.

Addresses the shared client behavior for:

Includes integration coverage for socketry/protocol-grpc#16. Downstream compatibility integration: socketry/async-grpc-compatible#7.

Transport-error conversion is separate work tracked by socketry/async-grpc-compatible#5. This PR preserves native transport exceptions and adds no response-body wrapper.

Validation: COVERAGE=PartialSummary bundle exec bake test (84 tests, 201 assertions; 100% line coverage), bundle exec rubocop, and bundle exec bake decode:index:coverage lib (29/29 public definitions). Tested on Ruby 4.0.7 against protocol-grpc 0.16.0, including HTTP/1 and HTTP/2 integration tests. The dependent compatibility suite also passes (55 tests, 224 assertions), including HTTP/2 coverage for status mapping, retained bodies, headers, and response cleanup.

CI note: the experimental TruffleRuby job on the preceding revision failed in Async/test fixture setup because Fiber.scheduler is unavailable. That matrix entry is configured with continue-on-error.

@samuel-williams-shopify
samuel-williams-shopify marked this pull request as ready for review September 24, 2026 01:38
@samuel-williams-shopify samuel-williams-shopify changed the title Validate gRPC responses and normalize transport failures Validate HTTP responses before decoding gRPC messages Sep 24, 2026
@samuel-williams-shopify samuel-williams-shopify changed the title Validate HTTP responses before decoding gRPC messages Reject invalid gRPC responses and preserve HTTP diagnostics Sep 24, 2026
@samuel-williams-shopify
samuel-williams-shopify merged commit b6ed06c into main Sep 24, 2026
24 of 28 checks passed
@samuel-williams-shopify
samuel-williams-shopify deleted the fix-grpc-interoperability branch September 24, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant