Skip to content

Commit c8a43ae

Browse files
committed
fixup
Signed-off-by: Matteo Collina <[email protected]>
1 parent 8b5e2c8 commit c8a43ae

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/dispatcher/client-h2.js

+12
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,18 @@ function writeH2 (client, request) {
405405
const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers
406406
request.onResponseStarted()
407407

408+
// Due to the stream nature, it is possible we face a race condition
409+
// where the stream has been assigned, but the request has been aborted
410+
// the request remains in-flight and headers hasn't been received yet
411+
// for those scenarios, best effort is to destroy the stream immediately
412+
// as there's no value to keep it open.
413+
if (request.aborted || request.completed) {
414+
const err = new RequestAbortedError()
415+
errorRequest(client, request, err)
416+
util.destroy(stream, err)
417+
return
418+
}
419+
408420
if (request.onHeaders(Number(statusCode), parseH2Headers(realHeaders), stream.resume.bind(stream), '') === false) {
409421
stream.pause()
410422
}

0 commit comments

Comments
 (0)