diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 6d0b6a1b72d377..3c8b51f30f3e1e 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)