Skip to content

Commit 81c08a1

Browse files
addaleaxMylesBorins
authored andcommitted
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: #20456 PR-URL: #18988 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f137c18 commit 81c08a1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/internal/http2/core.js

+5
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ class Http2Session extends EventEmitter {
11291129

11301130
// Destroy any pending and open streams
11311131
const cancel = new errors.Error('ERR_HTTP2_STREAM_CANCEL');
1132+
if (error) {
1133+
cancel.cause = error;
1134+
if (typeof error.message === 'string')
1135+
cancel.message += ` (caused by: ${error.message})`;
1136+
}
11321137
state.pendingStreams.forEach((stream) => stream.destroy(cancel));
11331138
state.streams.forEach((stream) => stream.destroy(error));
11341139

test/parallel/test-http2-client-onconnect-errors.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ function runTest(test) {
8888
req.on('error', errorMustCall);
8989
} else {
9090
client.on('error', errorMustCall);
91-
req.on('error', common.expectsError({
92-
code: 'ERR_HTTP2_STREAM_CANCEL'
93-
}));
91+
req.on('error', (err) => {
92+
common.expectsError({
93+
code: 'ERR_HTTP2_STREAM_CANCEL'
94+
})(err);
95+
common.expectsError({
96+
code: 'ERR_HTTP2_ERROR'
97+
})(err.cause);
98+
});
9499
}
95100

96101
req.on('end', common.mustCall());

0 commit comments

Comments
 (0)