Skip to content

Commit 8f3aeea

Browse files
islandryuRafaelGSS
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 0a15b00 commit 8f3aeea

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎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
conststate=this[kState];
708708

709-
if(state.closed||this.stream.destroyed)
709+
if(state.closed||this.stream.destroyed||this.stream.closed)
710710
returnthis;
711711
if(this[kStream].headersSent)
712712
thrownewERR_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+
constcommon=require('../common');
4+
if(!common.hasCrypto){common.skip('missing crypto');};
5+
consth2=require('http2');
6+
7+
constserver=h2.createServer((req,res)=>{
8+
conststream=req.stream;
9+
stream.close();
10+
res.writeHead(200,{'content-type': 'text/plain'});
11+
});
12+
13+
server.listen(0,common.mustCall(()=>{
14+
constport=server.address().port;
15+
constclient=h2.connect(`http://localhost:${port}`);
16+
constreq=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)