Skip to content

Commit 1dd744a

Browse files
davedoesdevdanielleadams
authored andcommitted
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>
1 parent cb6f0d3 commit 1dd744a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/internal/http2/core.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ function debugStream(id, sessionType, message, ...args) {
176176
}
177177

178178
function debugStreamObj(stream, message, ...args) {
179-
debugStream(stream[kID], stream[kSession][kType], message, ...args);
179+
const session = stream[kSession];
180+
const type = session ? session[kType] : undefined;
181+
debugStream(stream[kID], type, message, ...args);
180182
}
181183

182184
function debugSession(sessionType, message, ...args) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto) {
4+
common.skip('missing crypto');
5+
}
6+
7+
const http2 = require('http2');
8+
const assert = require('assert');
9+
10+
const server = http2.createServer();
11+
12+
server.on('session', common.mustCall(function(session) {
13+
session.on('stream', common.mustCall(function(stream) {
14+
stream.on('end', common.mustCall(function() {
15+
this.respond({
16+
':status': 200
17+
});
18+
this.write('foo');
19+
this.destroy();
20+
}));
21+
stream.resume();
22+
}));
23+
}));
24+
25+
server.listen(0, function() {
26+
const client = http2.connect(`http://localhost:${server.address().port}`);
27+
const stream = client.request({ ':method': 'POST' });
28+
stream.on('response', common.mustCall(function(headers) {
29+
assert.strictEqual(headers[':status'], 200);
30+
}));
31+
stream.on('close', common.mustCall(() => {
32+
client.close();
33+
server.close();
34+
}));
35+
stream.resume();
36+
stream.end();
37+
});

0 commit comments

Comments
 (0)