Skip to content

Commit 91be1dc

Browse files
apapirovskiBethGriggs
authored andcommitted
http2: delay closing stream
Delay automatically closing the stream with setImmediate in order to allow any pushStreams to be sent first. Backport-PR-URL: #22850 PR-URL: #20997 Fixes: #20992 Reviewed-By: James M Snell <[email protected]>
1 parent 5d29e2c commit 91be1dc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/http2/core.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,10 @@ class Http2Stream extends Duplex {
19021902
!(state.flags & STREAM_FLAGS_HAS_TRAILERS) &&
19031903
!state.didRead &&
19041904
this._readableState.flowing === null) {
1905-
this.close();
1905+
// By using setImmediate we allow pushStreams to make it through
1906+
// before the stream is officially closed. This prevents a bug
1907+
// in most browsers where those pushStreams would be rejected.
1908+
setImmediate(this.close.bind(this));
19061909
}
19071910
}
19081911
}
@@ -2137,7 +2140,7 @@ class ServerHttp2Stream extends Http2Stream {
21372140
let headRequest = false;
21382141
if (headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD)
21392142
headRequest = options.endStream = true;
2140-
options.readable = !options.endStream;
2143+
options.readable = false;
21412144

21422145
const headersList = mapToHeaders(headers);
21432146
if (!Array.isArray(headersList))

0 commit comments

Comments
 (0)