mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2873 from murgatroid99/grpc-js_http_error_resource_exhausted_fix
grpc-js: Prioritize HTTP status errors over message decoding errors
This commit is contained in:
commit
bae98b3d2f
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@grpc/grpc-js",
|
"name": "@grpc/grpc-js",
|
||||||
"version": "1.12.4",
|
"version": "1.12.5",
|
||||||
"description": "gRPC Library for Node - pure JS implementation",
|
"description": "gRPC Library for Node - pure JS implementation",
|
||||||
"homepage": "https://grpc.io/",
|
"homepage": "https://grpc.io/",
|
||||||
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,22 @@ export class Http2SubchannelCall implements SubchannelCall {
|
||||||
try {
|
try {
|
||||||
messages = this.decoder.write(data);
|
messages = this.decoder.write(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
/* 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);
|
this.cancelWithStatus(Status.RESOURCE_EXHAUSTED, (e as Error).message);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue