• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const http2 = require('http2');
8const net = require('net');
9const http2util = require('../common/http2');
10
11// Test that ping flooding causes the session to be torn down
12
13const kSettings = new http2util.SettingsFrame();
14const kPingAck = new http2util.PingFrame(true);
15
16const server = http2.createServer();
17
18server.on('stream', common.mustNotCall());
19server.on('session', common.mustCall((session) => {
20  session.on('error', common.expectsError({
21    code: 'ERR_HTTP2_ERROR',
22    message: 'Protocol error'
23  }));
24  session.on('close', common.mustCall(() => server.close()));
25}));
26
27server.listen(0, common.mustCall(() => {
28  const client = net.connect(server.address().port);
29
30  client.on('connect', common.mustCall(() => {
31    client.write(http2util.kClientMagic, () => {
32      client.write(kSettings.data);
33      // Send an unsolicited ping ack
34      client.write(kPingAck.data);
35    });
36  }));
37
38  // An error event may or may not be emitted, depending on operating system
39  // and timing. We do not really care if one is emitted here or not, as the
40  // error on the server side is what we are testing for. Do not make this
41  // a common.mustCall() and there's no need to check the error details.
42  client.on('error', () => {});
43}));
44