Skip to content

Commit

Permalink
http2: delay closing stream
Browse files Browse the repository at this point in the history
Delay automatically closing the stream with setImmediate in order
to allow any pushStreams to be sent first.

PR-URL: #20997
Fixes: #20992
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
apapirovski authored and addaleax committed Jun 1, 2018
1 parent 7e1f610 commit 2a9912c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,10 @@ class Http2Stream extends Duplex {
!(state.flags & STREAM_FLAGS_HAS_TRAILERS) &&
!state.didRead &&
this.readableFlowing === null) {
this.close();
// By using setImmediate we allow pushStreams to make it through
// before the stream is officially closed. This prevents a bug
// in most browsers where those pushStreams would be rejected.
setImmediate(this.close.bind(this));
}
}
}
Expand Down Expand Up @@ -2178,7 +2181,7 @@ class ServerHttp2Stream extends Http2Stream {
let headRequest = false;
if (headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD)
headRequest = options.endStream = true;
options.readable = !options.endStream;
options.readable = false;

const headersList = mapToHeaders(headers);
if (!Array.isArray(headersList))
Expand Down

0 comments on commit 2a9912c

Please sign in to comment.