Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2153,14 +2153,7 @@ function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
stream.setTimeout(0);
stream.removeAllListeners('timeout');

// Emit 'aborted' if the user hadn't ended the writable yet. This is
// unusual and doesn't match 'error' but is deprecated & preserved for
// backward compat (DEP0207).
const { ending } = stream._writableState;
if (!ending && !stream.aborted) {
state.flags |= STREAM_FLAGS_ABORTED;
stream.emit('aborted');
}

if (rstStreamStatus !== kNoRstStream) {
// If the user already called .end() and writes are still draining,
Expand All @@ -2174,6 +2167,14 @@ function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
}
}

// Emit 'aborted' if the user hadn't ended the writable yet. This is
// unusual and doesn't match 'error' but is deprecated & preserved for
// backward compat (DEP0207).
if (!ending && !stream.aborted) {
state.flags |= STREAM_FLAGS_ABORTED;
stream.emit('aborted');
}

if (type === NGHTTP2_SESSION_CLIENT) {
if (onClientStreamCloseChannel.hasSubscribers) {
onClientStreamCloseChannel.publish({ stream });
Expand Down
32 changes: 32 additions & 0 deletions test/parallel/test-http2-close-aborted-destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const { NGHTTP2_CANCEL } = http2.constants;

const server = http2.createServer();

server.on('stream', common.mustCall((stream) => {
stream.respond();
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ABORTED',
}));
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, NGHTTP2_CANCEL);
server.close();
}));
}));

server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request({ ':method': 'POST' });

req.on('aborted', common.mustCall(() => req.destroy()));
req.on('close', common.mustCall(() => client.close()));
req.on('response', common.mustCall(() => {
req.close(NGHTTP2_CANCEL);
}));
}));
Loading