diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 0302d535c3731d..a020838493fbab 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..0cf84dd10d2344 --- /dev/null +++ b/test/parallel/test-http2-server-session-destroy.js @@ -0,0 +1,16 @@ +'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.mustCall(() => { + h2.connect(`http://localhost:${server.address().port}`, (session) => { + session.request({ ':method': 'POST' }).end(common.mustCall(() => { + session.destroy(); + server.close(); + })); + }); +}));