Skip to content

Commit f4aed8c

Browse files
mcollinaBethGriggs
authored andcommitted
http2: make compat writeHead not crash if the stream is destroyed
Fixes: #24470 PR-URL: #24723 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 46e37ad commit f4aed8c

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎lib/internal/http2/compat.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ class Http2ServerResponse extends Stream {
568568
if(this[kStream].headersSent)
569569
thrownewERR_HTTP2_HEADERS_SENT();
570570

571+
// If the stream is destroyed, we return false,
572+
// like require('http').
573+
if(this.stream.destroyed)
574+
returnfalse;
575+
571576
if(typeofstatusMessage==='string')
572577
statusMessageWarn();
573578

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
if(!common.hasCrypto)
5+
common.skip('missing crypto');
6+
consthttp2=require('http2');
7+
8+
// Check that writeHead, write and end do not crash in compatibility mode
9+
10+
constserver=http2.createServer(common.mustCall((req,res)=>{
11+
// destroy the stream first
12+
req.stream.destroy();
13+
14+
res.writeHead(200);
15+
res.write('hello ');
16+
res.end('world');
17+
}));
18+
19+
server.listen(0,common.mustCall(()=>{
20+
constclient=http2.connect(`http://localhost:${server.address().port}`);
21+
22+
constreq=client.request();
23+
req.on('response',common.mustNotCall());
24+
req.on('close',common.mustCall((arg)=>{
25+
client.close();
26+
server.close();
27+
}));
28+
req.resume();
29+
}));

0 commit comments

Comments
 (0)