1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const http2 = require('http2'); 9const net = require('net'); 10 11const http2util = require('../common/http2'); 12 13// Test that settings flooding causes the session to be torn down 14 15const kSettings = new http2util.SettingsFrame(); 16 17const server = http2.createServer(); 18 19let interval; 20 21server.on('stream', common.mustNotCall()); 22server.on('session', common.mustCall((session) => { 23 session.on('error', (e) => { 24 assert.strictEqual(e.code, 'ERR_HTTP2_ERROR'); 25 assert(e.message.includes('Flooding was detected')); 26 clearInterval(interval); 27 }); 28 29 session.on('close', common.mustCall(() => { 30 server.close(); 31 })); 32})); 33 34server.listen(0, common.mustCall(() => { 35 const client = net.connect(server.address().port); 36 37 // nghttp2 uses a limit of 10000 items in it's outbound queue. 38 // If this number is exceeded, a flooding error is raised. 39 // TODO(jasnell): Unfortunately, this test is inherently flaky because 40 // it is entirely dependent on how quickly the server is able to handle 41 // the inbound frames and whether those just happen to overflow nghttp2's 42 // outbound queue. The threshold at which the flood error occurs can vary 43 // from one system to another, and from one test run to another. 44 client.on('connect', common.mustCall(() => { 45 client.write(http2util.kClientMagic, () => { 46 interval = setInterval(() => { 47 for (let n = 0; n < 10000; n++) 48 client.write(kSettings.data); 49 }, 1); 50 }); 51 })); 52 53 // An error event may or may not be emitted, depending on operating system 54 // and timing. We do not really care if one is emitted here or not, as the 55 // error on the server side is what we are testing for. Do not make this 56 // a common.mustCall() and there's no need to check the error details. 57 client.on('error', () => {}); 58})); 59