Skip to content

Commit 2ce2764

Browse files
islandryuaduh95
authored andcommitted
http2: skip writeHead if stream is closed
Fixes: #57416 PR-URL: #57686 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
1 parent c3a4c1f commit 2ce2764

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/internal/http2/compat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class Http2ServerResponse extends Stream {
706706
writeHead(statusCode, statusMessage, headers) {
707707
const state = this[kState];
708708

709-
if (state.closed || this.stream.destroyed)
709+
if (state.closed || this.stream.destroyed || this.stream.closed)
710710
return this;
711711
if (this[kStream].headersSent)
712712
throw new ERR_HTTP2_HEADERS_SENT();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto) { common.skip('missing crypto'); };
5+
const h2 = require('http2');
6+
7+
const server = h2.createServer((req, res) => {
8+
const stream = req.stream;
9+
stream.close();
10+
res.writeHead(200, { 'content-type': 'text/plain' });
11+
});
12+
13+
server.listen(0, common.mustCall(() => {
14+
const port = server.address().port;
15+
const client = h2.connect(`http://localhost:${port}`);
16+
const req = client.request({ ':path': '/' });
17+
req.on('response', common.mustNotCall('head after close should not be sent'));
18+
req.on('end', common.mustCall(() => {
19+
client.close();
20+
server.close();
21+
}));
22+
req.end();
23+
}));

0 commit comments

Comments
 (0)