From d8bdb211ebbca5a79fd0f9ca9fd6125c2e55851a Mon Sep 17 00:00:00 2001 From: Devraj Mehta Date: Mon, 26 Jun 2023 15:53:58 -0400 Subject: [PATCH] http2: send RST code 8 when abort called Fixes: #47321 --- lib/internal/http2/core.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 6d0b6a1b72d3775..3c8b51f30f3e1ef 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -2318,10 +2318,17 @@ class Http2Stream extends Duplex { // this stream's close and destroy operations. // Previously, this always overrode a successful close operation code // NGHTTP2_NO_ERROR (0) with sessionCode because the use of the || operator. - const code = (err != null ? - (sessionCode || NGHTTP2_INTERNAL_ERROR) : - (this.closed ? this.rstCode : sessionCode) - ); + let code = this.closed ? this.rstCode : sessionCode; + if (err != null) { + if (sessionCode) { + code = sessionCode; + } else if (err instanceof AbortError) { + // Enables using AbortController to cancel requests with RST code 8. + code = NGHTTP2_CANCEL; + } else { + code = NGHTTP2_INTERNAL_ERROR; + } + } const hasHandle = handle !== undefined; if (!this.closed)