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: #20997Fixes: #20992 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5d29e2c commit 91be1dc

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎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._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
letheadRequest=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
constheadersList=mapToHeaders(headers);
21432146
if(!Array.isArray(headersList))

0 commit comments

Comments
 (0)