Skip to content

Commit cc28223

Browse files
addaleaxBethGriggs
authored andcommitted
test: apply test-http2-max-session-memory-leak from v12.x
Refs: #27914 Backport-PR-URL: #29124 PR-URL: #29122 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 073108c commit cc28223

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
if(!common.hasCrypto)
4+
common.skip('missing crypto');
5+
consthttp2=require('http2');
6+
7+
// Regression test for https://github.com/nodejs/node/issues/27416.
8+
// Check that received data is accounted for correctly in the maxSessionMemory
9+
// mechanism.
10+
11+
constbodyLength=8192;
12+
constmaxSessionMemory=1;// 1 MB
13+
constrequestCount=1000;
14+
15+
constserver=http2.createServer({ maxSessionMemory });
16+
server.on('stream',(stream)=>{
17+
stream.respond();
18+
stream.end();
19+
});
20+
21+
server.listen(common.mustCall(()=>{
22+
constclient=http2.connect(`http://localhost:${server.address().port}`,{
23+
maxSessionMemory
24+
});
25+
26+
functionrequest(){
27+
returnnewPromise((resolve,reject)=>{
28+
conststream=client.request({
29+
':method': 'POST',
30+
'content-length': bodyLength
31+
});
32+
stream.on('error',reject);
33+
stream.on('response',resolve);
34+
stream.end('a'.repeat(bodyLength));
35+
});
36+
}
37+
38+
(async()=>{
39+
for(leti=0;i<requestCount;i++){
40+
awaitrequest();
41+
}
42+
43+
client.close();
44+
server.close();
45+
})().then(common.mustCall());
46+
}));

0 commit comments

Comments
 (0)