1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5const fixtures = require('../common/fixtures'); 6const http2 = require('http2'); 7 8// Regression test for https://github.com/nodejs/node/issues/29353. 9// Test that it’s okay for an HTTP2 + TLS server to destroy a stream instance 10// while reading it. 11 12const server = http2.createSecureServer({ 13 key: fixtures.readKey('agent2-key.pem'), 14 cert: fixtures.readKey('agent2-cert.pem') 15}); 16 17const filenames = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; 18 19server.on('stream', common.mustCall((stream) => { 20 function write() { 21 stream.write('a'.repeat(10240)); 22 stream.once('drain', write); 23 } 24 write(); 25}, filenames.length)); 26 27server.listen(0, common.mustCall(() => { 28 const client = http2.connect(`https://localhost:${server.address().port}`, { 29 ca: fixtures.readKey('agent2-cert.pem'), 30 servername: 'agent2' 31 }); 32 33 let destroyed = 0; 34 for (const entry of filenames) { 35 const stream = client.request({ 36 ':path': `/${entry}` 37 }); 38 stream.once('data', common.mustCall(() => { 39 stream.destroy(); 40 41 if (++destroyed === filenames.length) { 42 client.destroy(); 43 server.close(); 44 } 45 })); 46 } 47})); 48