From 92bd7b522a6595cb81d311f191c667d8ac27f3f8 Mon Sep 17 00:00:00 2001 From: David Halls Date: Wed, 4 Nov 2020 00:01:33 +0000 Subject: [PATCH] http2: fix error stream write followed by destroy PR-URL: https://github.com/nodejs/node/pull/35951 Reviewed-By: Matteo Collina Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Rich Trott --- lib/internal/http2/core.js | 4 +- .../test-http2-destroy-after-write.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http2-destroy-after-write.js diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 2576600fd66e19..3064c9893dc3a0 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -167,7 +167,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) { diff --git a/test/parallel/test-http2-destroy-after-write.js b/test/parallel/test-http2-destroy-after-write.js new file mode 100644 index 00000000000000..399df015b8879e --- /dev/null +++ b/test/parallel/test-http2-destroy-after-write.js @@ -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(); +});