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: nodejs#20997
Fixes: nodejs#20992
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
apapirovski authored and kjin committed Sep 25, 2018
1 parent 357afab commit 75026dc
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 @@ -1902,7 +1902,10 @@ class Http2Stream extends Duplex {
!(state.flags & STREAM_FLAGS_HAS_TRAILERS) &&
!state.didRead &&
this._readableState.flowing === 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 @@ -2137,7 +2140,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 75026dc

Please sign in to comment.