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
http2: fix error stream write followed by destroy
PR-URL: #35951
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
davedoesdev authored and Trott committed Nov 6, 2020
commit 1fd7d8e90387a83fe3a2566bdac147c1b33cdbcc
4 changes: 3 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ function debugStream(id, sessionType, message, ...args) {
}

function debugStreamObj(stream, message, ...args) {
debugStream(stream[kID], stream[kSession][kType], message, ...args);
const session = stream[kSession];
const type = session ? session[kType] : undefined;
debugStream(stream[kID], type, message, ...args);
}

function debugSession(sessionType, message, ...args) {
Expand Down
37 changes: 37 additions & 0 deletions test/parallel/test-http2-destroy-after-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}

const http2 = require('http2');
const assert = require('assert');

const server = http2.createServer();

server.on('session', common.mustCall(function(session) {
session.on('stream', common.mustCall(function(stream) {
stream.on('end', common.mustCall(function() {
this.respond({
':status': 200
});
this.write('foo');
this.destroy();
}));
stream.resume();
}));
}));

server.listen(0, function() {
const client = http2.connect(`http://localhost:${server.address().port}`);
const stream = client.request({ ':method': 'POST' });
stream.on('response', common.mustCall(function(headers) {
assert.strictEqual(headers[':status'], 200);
}));
stream.on('close', common.mustCall(() => {
client.close();
server.close();
}));
stream.resume();
stream.end();
});