Skip to content

Commit

Permalink
http2: use original error for cancelling pending streams
Browse files Browse the repository at this point in the history
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.

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]>
  • Loading branch information
addaleax committed Mar 2, 2018
1 parent 67b7d54 commit c197c78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,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));

Expand Down
11 changes: 8 additions & 3 deletions test/parallel/test-http2-client-onconnect-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,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());
Expand Down

0 comments on commit c197c78

Please sign in to comment.