1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) { 4 common.skip('missing crypto'); 5} 6 7// Issue #23116 8// nghttp2 keeps closed stream structures around in memory (couple of hundred 9// bytes each) until a session is closed. It does this to maintain the priority 10// tree. However, it limits the number of requests that can be made in a 11// session before our memory tracking (correctly) kicks in. 12// The fix is to tell nghttp2 to forget about closed streams. We don't make use 13// of priority anyway. 14// Without the fix, this test fails at ~40k requests with an exception: 15// Error [ERR_HTTP2_STREAM_ERROR]: Stream closed with error code 16// NGHTTP2_ENHANCE_YOUR_CALM 17 18const http2 = require('http2'); 19const assert = require('assert'); 20 21const server = http2.createServer({ maxSessionMemory: 1 }); 22 23server.on('session', function(session) { 24 session.on('stream', function(stream) { 25 stream.on('end', common.mustCall(function() { 26 this.respond({ 27 ':status': 200 28 }, { 29 endStream: true 30 }); 31 })); 32 stream.resume(); 33 }); 34}); 35 36server.listen(0, function() { 37 const client = http2.connect(`http://localhost:${server.address().port}`); 38 39 function next(i) { 40 if (i === 10000) { 41 client.close(); 42 return server.close(); 43 } 44 const stream = client.request({ ':method': 'POST' }); 45 stream.on('response', common.mustCall(function(headers) { 46 assert.strictEqual(headers[':status'], 200); 47 this.on('close', common.mustCall(() => next(i + 1))); 48 })); 49 stream.end(); 50 } 51 52 next(0); 53}); 54