• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7// Issue #24984
8// 'close' event isn't emitted on a TLS connection if it's been written to
9// (but 'end' and 'finish' events are). Without a fix, this test won't exit.
10
11const tls = require('tls');
12const fixtures = require('../common/fixtures');
13let cconn = null;
14let sconn = null;
15let read_len = 0;
16const buffer_size = 1024 * 1024;
17
18function test() {
19  if (cconn && sconn) {
20    cconn.resume();
21    sconn.resume();
22    sconn.end(Buffer.alloc(buffer_size));
23  }
24}
25
26const server = tls.createServer({
27  key: fixtures.readKey('agent1-key.pem'),
28  cert: fixtures.readKey('agent1-cert.pem')
29}, (c) => {
30  c.on('close', common.mustCall(() => server.close()));
31  sconn = c;
32  test();
33}).listen(0, common.mustCall(function() {
34  tls.connect(this.address().port, {
35    rejectUnauthorized: false
36  }, common.mustCall(function() {
37    cconn = this;
38    cconn.on('data', (d) => {
39      read_len += d.length;
40      if (read_len === buffer_size) {
41        cconn.end();
42      }
43    });
44    test();
45  }));
46}));
47