Skip to content

Commit

Permalink
Merge pull request #2873 from murgatroid99/grpc-js_http_error_resourc…
Browse files Browse the repository at this point in the history
…e_exhausted_fix

grpc-js: Prioritize HTTP status errors over message decoding errors
  • Loading branch information
murgatroid99 authored Dec 18, 2024
2 parents e9359ef + 63d9717 commit bae98b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.12.4",
"version": "1.12.5",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
17 changes: 16 additions & 1 deletion packages/grpc-js/src/subchannel-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,22 @@ export class Http2SubchannelCall implements SubchannelCall {
try {
messages = this.decoder.write(data);
} catch (e) {
this.cancelWithStatus(Status.RESOURCE_EXHAUSTED, (e as Error).message);
/* Some servers send HTML error pages along with HTTP status codes.
* When the client attempts to parse this as a length-delimited
* message, the parsed message size is greater than the default limit,
* resulting in a message decoding error. In that situation, the HTTP
* error code information is more useful to the user than the
* RESOURCE_EXHAUSTED error is, so we report that instead. Normally,
* we delay processing the HTTP status until after the stream ends, to
* prioritize reporting the gRPC status from trailers if it is present,
* but when there is a message parsing error we end the stream early
* before processing trailers. */
if (this.httpStatusCode !== undefined && this.httpStatusCode !== 200) {
const mappedStatus = mapHttpStatusCode(this.httpStatusCode);
this.cancelWithStatus(mappedStatus.code, mappedStatus.details);
} else {
this.cancelWithStatus(Status.RESOURCE_EXHAUSTED, (e as Error).message);
}
return;
}

Expand Down

0 comments on commit bae98b3

Please sign in to comment.