From 091238a9a74f342eef12dcaa962cda80319dcfb7 Mon Sep 17 00:00:00 2001 From: leeight Date: Wed, 21 Nov 2018 16:53:15 +0800 Subject: [PATCH] http2: fix session[kSession] undefined issue `finishSessionDestroy` session cleanup when already done. PR-URL: https://github.com/nodejs/node/pull/24547 Fixes: https://github.com/nodejs/node/issues/24546 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Ouyang Yadong Reviewed-By: Colin Ihrig --- lib/internal/http2/core.js | 1 + .../test-http2-server-session-destroy.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/parallel/test-http2-server-session-destroy.js diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 4a2ece2333fc80..80bcef5fa21633 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1989,6 +1989,7 @@ class Http2Stream extends Duplex { // attempt to gracefully close the session. const state = this[kState]; if (this.headersSent && + this[kSession] && this[kSession][kType] === NGHTTP2_SESSION_SERVER && !(state.flags & STREAM_FLAGS_HAS_TRAILERS) && !state.didRead && diff --git a/test/parallel/test-http2-server-session-destroy.js b/test/parallel/test-http2-server-session-destroy.js new file mode 100644 index 00000000000000..9b7f126510757c --- /dev/null +++ b/test/parallel/test-http2-server-session-destroy.js @@ -0,0 +1,20 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const h2 = require('http2'); + +const server = h2.createServer(); +server.listen(0, common.localhostIPv4, common.mustCall(() => { + const afterConnect = common.mustCall((session) => { + session.request({ ':method': 'POST' }).end(common.mustCall(() => { + session.destroy(); + server.close(); + })); + }); + + const port = server.address().port; + const host = common.localhostIPv4; + h2.connect('http://' + host + ':' + port, afterConnect); +}));