Skip to content

Commit c7c28c1

Browse files
apapirovskikjin
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: nodejs#20997 Fixes: nodejs#20992 Reviewed-By: James M Snell <[email protected]>
1 parent 2c3178f commit c7c28c1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/http2/core.js

Lines changed: 5 additions & 2 deletions
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.readableFlowing === 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)