Skip to content

Commit 729a3f5

Browse files
authored
Merge pull request #2695 from murgatroid99/grpc-js_avoid_extra_rst_stream
grpc-js: Avoid sending redundant RST_STREAMs from the client
2 parents c1df94e + 14f1d02 commit 729a3f5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.10.3",
3+
"version": "1.10.4",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/subchannel-call.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export class Http2SubchannelCall implements SubchannelCall {
105105

106106
private internalError: SystemError | null = null;
107107

108+
private serverEndedCall = false;
109+
108110
constructor(
109111
private readonly http2Stream: http2.ClientHttp2Stream,
110112
private readonly callEventTracker: CallEventTracker,
@@ -182,6 +184,7 @@ export class Http2SubchannelCall implements SubchannelCall {
182184
this.maybeOutputStatus();
183185
});
184186
http2Stream.on('close', () => {
187+
this.serverEndedCall = true;
185188
/* Use process.next tick to ensure that this code happens after any
186189
* "error" event that may be emitted at about the same time, so that
187190
* we can bubble up the error message from that event. */
@@ -400,6 +403,7 @@ export class Http2SubchannelCall implements SubchannelCall {
400403
}
401404

402405
private handleTrailers(headers: http2.IncomingHttpHeaders) {
406+
this.serverEndedCall = true;
403407
this.callEventTracker.onStreamEnd(true);
404408
let headersString = '';
405409
for (const header of Object.keys(headers)) {
@@ -445,7 +449,15 @@ export class Http2SubchannelCall implements SubchannelCall {
445449
private destroyHttp2Stream() {
446450
// The http2 stream could already have been destroyed if cancelWithStatus
447451
// is called in response to an internal http2 error.
448-
if (!this.http2Stream.destroyed) {
452+
if (this.http2Stream.destroyed) {
453+
return;
454+
}
455+
/* If the server ended the call, sending an RST_STREAM is redundant, so we
456+
* just half close on the client side instead to finish closing the stream.
457+
*/
458+
if (this.serverEndedCall) {
459+
this.http2Stream.end();
460+
} else {
449461
/* If the call has ended with an OK status, communicate that when closing
450462
* the stream, partly to avoid a situation in which we detect an error
451463
* RST_STREAM as a result after we have the status */

0 commit comments

Comments
 (0)