Skip to content

Commit

Permalink
Merge pull request #2193 from murgatroid99/grpc-js_stream_flow_after_end
Browse files Browse the repository at this point in the history
grpc-js: Drain incoming http2 data after outputting status
  • Loading branch information
murgatroid99 committed Aug 15, 2022
2 parents 6d6c58c + 3f4418f commit a5429ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.6.9",
"version": "1.6.10",
"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
13 changes: 10 additions & 3 deletions packages/grpc-js/src/call-stream.ts
Expand Up @@ -329,6 +329,11 @@ export class Http2CallStream implements Call {
process.nextTick(() => {
this.listener?.onReceiveStatus(filteredStatus);
});
/* Leave the http2 stream in flowing state to drain incoming messages, to
* ensure that the stream closure completes. The call stream already does
* not push more messages after the status is output, so the messages go
* nowhere either way. */
this.http2Stream?.resume();
if (this.subchannel) {
this.subchannel.callUnref();
this.subchannel.removeDisconnectListener(this.disconnectListener);
Expand Down Expand Up @@ -577,6 +582,11 @@ export class Http2CallStream implements Call {
this.handleTrailers(headers);
});
stream.on('data', (data: Buffer) => {
/* If the status has already been output, allow the http2 stream to
* drain without processing the data. */
if (this.statusOutput) {
return;
}
this.trace('receive HTTP/2 data frame of length ' + data.length);
const messages = this.decoder.write(data);

Expand Down Expand Up @@ -688,9 +698,6 @@ export class Http2CallStream implements Call {
}
this.streamEndWatchers.forEach(watcher => watcher(false));
});
if (!this.pendingRead) {
stream.pause();
}
if (this.pendingWrite) {
if (!this.pendingWriteCallback) {
throw new Error('Invalid state in write handling code');
Expand Down

0 comments on commit a5429ad

Please sign in to comment.