Skip to content

Commit 2a9912c

Browse files
apapirovskiaddaleax
authored andcommitted
http2: delay closing stream
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]>
1 parent 7e1f610 commit 2a9912c

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
@@ -1906,7 +1906,10 @@ class Http2Stream extends Duplex {
19061906
!(state.flags & STREAM_FLAGS_HAS_TRAILERS) &&
19071907
!state.didRead &&
19081908
this.readableFlowing === null) {
1909-
this.close();
1909+
// By using setImmediate we allow pushStreams to make it through
1910+
// before the stream is officially closed. This prevents a bug
1911+
// in most browsers where those pushStreams would be rejected.
1912+
setImmediate(this.close.bind(this));
19101913
}
19111914
}
19121915
}
@@ -2178,7 +2181,7 @@ class ServerHttp2Stream extends Http2Stream {
21782181
let headRequest = false;
21792182
if (headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD)
21802183
headRequest = options.endStream = true;
2181-
options.readable = !options.endStream;
2184+
options.readable = false;
21822185

21832186
const headersList = mapToHeaders(headers);
21842187
if (!Array.isArray(headersList))

0 commit comments

Comments
 (0)