From 2a9912c0df555c6cb7b7f763bd45320216d2b3de Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Mon, 28 May 2018 09:20:51 +0200 Subject: [PATCH] http2: delay closing stream Delay automatically closing the stream with setImmediate in order to allow any pushStreams to be sent first. PR-URL: https://github.com/nodejs/node/pull/20997 Fixes: https://github.com/nodejs/node/issues/20992 Reviewed-By: James M Snell --- lib/internal/http2/core.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 39d456fb75905f..7e2faa97bf02da 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1906,7 +1906,10 @@ class Http2Stream extends Duplex { !(state.flags & STREAM_FLAGS_HAS_TRAILERS) && !state.didRead && this.readableFlowing === 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)); } } } @@ -2178,7 +2181,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))