Skip to content

Commit d90594a

Browse files
joyeecheungrichardlau
authored andcommitted
test: deflake test-http2-large-write-multiple-requests
If the server is not referenced, it might go away too soon and the client may not get enough ends for it to close itself, resulting a timeout. This patch updates the test to simply close the server when enough requests have been processed, and keep the server referenced while the test is ongoing. Drive-by: add more logs to facilitate debugging. PR-URL: #51863 Refs: nodejs/reliability#791 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 48959dd commit d90594a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎test/parallel/test-http2-large-write-multiple-requests.js‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const common = require('../common');
33
if(!common.hasCrypto)
44
common.skip('missing crypto');
55

6+
// This tests that the http2 server sends data early when it accumulates
7+
// enough from ongoing requests to avoid DoS as mitigation for
8+
// CVE-2019-9517 and CVE-2019-9511.
9+
// Added by https://github.com/nodejs/node/commit/8a4a193
610
constfixtures=require('../common/fixtures');
711
constassert=require('assert');
812
consthttp2=require('http2');
@@ -12,18 +16,20 @@ const content = fixtures.readSync('person-large.jpg');
1216
constserver=http2.createServer({
1317
maxSessionMemory: 1000
1418
});
19+
letstreamCount=0;
1520
server.on('stream',(stream,headers)=>{
1621
stream.respond({
1722
'content-type': 'image/jpeg',
1823
':status': 200
1924
});
2025
stream.end(content);
26+
console.log('server sends content',++streamCount);
2127
});
22-
server.unref();
2328

2429
server.listen(0,common.mustCall(()=>{
2530
constclient=http2.connect(`http://localhost:${server.address().port}/`);
2631

32+
letendCount=0;
2733
letfinished=0;
2834
for(leti=0;i<100;i++){
2935
constreq=client.request({':path': '/'}).end();
@@ -32,8 +38,16 @@ server.listen(0, common.mustCall(() =>{
3238
chunks.push(chunk);
3339
});
3440
req.on('end',common.mustCall(()=>{
41+
console.log('client receives content',++endCount);
3542
assert.deepStrictEqual(Buffer.concat(chunks),content);
36-
if(++finished===100)client.close();
43+
44+
if(++finished===100){
45+
client.close();
46+
server.close();
47+
}
3748
}));
49+
req.on('error',(e)=>{
50+
console.log('client error',e);
51+
});
3852
}
3953
}));

0 commit comments

Comments
(0)