From 81c08a18249815feaf55cc2e3e4e92eac9357ea6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 25 Feb 2018 21:46:10 +0100 Subject: [PATCH] http2: use original error for cancelling pending streams Previously, if `session.destroy()` was called with an error object, the information contained in it would be discarded and a generic `ERR_HTTP2_STREAM_CANCEL` would be used for all pending streams. Instead, make the information from the original error object available. Backport-PR-URL: https://github.com/nodejs/node/pull/20456 PR-URL: https://github.com/nodejs/node/pull/18988 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/internal/http2/core.js | 5 +++++ test/parallel/test-http2-client-onconnect-errors.js | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 80c64c7ba3048b..0a3bcaf2e0cbbd 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1129,6 +1129,11 @@ class Http2Session extends EventEmitter { // Destroy any pending and open streams const cancel = new errors.Error('ERR_HTTP2_STREAM_CANCEL'); + if (error) { + cancel.cause = error; + if (typeof error.message === 'string') + cancel.message += ` (caused by: ${error.message})`; + } state.pendingStreams.forEach((stream) => stream.destroy(cancel)); state.streams.forEach((stream) => stream.destroy(error)); diff --git a/test/parallel/test-http2-client-onconnect-errors.js b/test/parallel/test-http2-client-onconnect-errors.js index 44fe6875602187..af67a0d0ae27db 100644 --- a/test/parallel/test-http2-client-onconnect-errors.js +++ b/test/parallel/test-http2-client-onconnect-errors.js @@ -88,9 +88,14 @@ function runTest(test) { req.on('error', errorMustCall); } else { client.on('error', errorMustCall); - req.on('error', common.expectsError({ - code: 'ERR_HTTP2_STREAM_CANCEL' - })); + req.on('error', (err) => { + common.expectsError({ + code: 'ERR_HTTP2_STREAM_CANCEL' + })(err); + common.expectsError({ + code: 'ERR_HTTP2_ERROR' + })(err.cause); + }); } req.on('end', common.mustCall());