Skip to content

Commit

Permalink
http2: Abort calls destroy with an AbortError
Browse files Browse the repository at this point in the history
- Builds on nodejs#36048 and nodejs#36084
- Modify test to verify this fact
  • Loading branch information
MadaraUchiha committed Nov 21, 2020
1 parent 05f68a2 commit dc99724
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const {
ERR_OUT_OF_RANGE,
ERR_SOCKET_CLOSED
},
hideStackFrames
hideStackFrames,
AbortError
} = require('internal/errors');
const {
isUint32,
Expand Down Expand Up @@ -1725,7 +1726,7 @@ class ClientHttp2Session extends Http2Session {
const { signal } = options;
if (signal) {
validateAbortSignal(signal, 'options.signal');
const listener = () => stream.destroy();
const listener = () => stream.destroy(new AbortError());
signal.addEventListener('abort', listener);
stream.once('close', () => {
signal.removeEventListener('abort', listener);
Expand Down
20 changes: 13 additions & 7 deletions test/parallel/test-http2-client-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,31 @@ const Countdown = require('../common/countdown');
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
client.on('close', common.mustCall());
client.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ECONNREFUSED');
assert.strictEqual(signal[kEvents].get('abort'), undefined);
server.close();
}));


const { signal } = controller;
assert.strictEqual(signal[kEvents].get('abort'), undefined);

client.on('error', common.mustCall(() => {
// After underlying stream dies, signal listener detached
assert.strictEqual(signal[kEvents].get('abort'), undefined);
}));

const req = client.request({}, { signal });

req.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ABORT_ERR');
assert.strictEqual(err.name, 'AbortError');
}));
req.on('close', common.mustCall(() => server.close()));

assert.strictEqual(req.aborted, false);
assert.strictEqual(req.destroyed, false);
// Signal listener attached
assert.strictEqual(signal[kEvents].get('abort').size, 1);

controller.abort();

assert.strictEqual(req.aborted, false);
assert.strictEqual(req.destroyed, true);
req.on('close', common.mustCall(() => server.close()));
}));
}

0 comments on commit dc99724

Please sign in to comment.