• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5const fixtures = require('../common/fixtures');
6
7// This test ensures that Node.js doesn't incur a segfault while accessing
8// TLSWrap fields after the parent handle was destroyed.
9// https://github.com/nodejs/node/issues/5108
10
11const assert = require('assert');
12const tls = require('tls');
13
14const options = {
15  key: fixtures.readKey('agent1-key.pem'),
16  cert: fixtures.readKey('agent1-cert.pem')
17};
18
19const server = tls.createServer(options, function(s) {
20  s.end('hello');
21}).listen(0, function() {
22  const opts = {
23    port: this.address().port,
24    rejectUnauthorized: false
25  };
26  const client = tls.connect(opts, function() {
27    putImmediate(client);
28  });
29  client.resume();
30});
31
32function putImmediate(client) {
33  setImmediate(function() {
34    if (client.ssl) {
35      const fd = client.ssl.fd;
36      assert(!!fd);
37      putImmediate(client);
38    } else {
39      server.close();
40    }
41  });
42}
43