• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const http2 = require('http2');
7const v8 = require('v8');
8
9// Regression test for https://github.com/nodejs/node/issues/28088:
10// Verify that Http2Settings and Http2Ping objects don't reference the session
11// after it is destroyed, either because they are detached from it or have been
12// destroyed themselves.
13
14for (const variant of ['ping', 'settings']) {
15  const server = http2.createServer();
16  server.on('session', common.mustCall((session) => {
17    if (variant === 'ping') {
18      session.ping(common.expectsError({
19        code: 'ERR_HTTP2_PING_CANCEL'
20      }));
21    } else {
22      session.settings(undefined, common.mustNotCall());
23    }
24
25    session.on('close', common.mustCall(() => {
26      v8.getHeapSnapshot().resume();
27      server.close();
28    }));
29    session.destroy();
30  }));
31
32  server.listen(0, common.mustCall(() => {
33    const client = http2.connect(`http://localhost:${server.address().port}`,
34                                 common.mustCall());
35    client.on('error', (err) => {
36      // We destroy the session so it's possible to get ECONNRESET here.
37      if (err.code !== 'ECONNRESET')
38        throw err;
39    });
40  }));
41}
42