Skip to content

Commit

Permalink
Add a test for the TLS reinitialization duplicate-listeners bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Oct 16, 2023
1 parent 43c4a9e commit f531d15
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/parallel/test-tls-reinitialize-listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
}

const events = require('events');
const fixtures = require('../common/fixtures');
const tls = require('tls');
const { kReinitializeHandle } = require('internal/net');

// Test that repeated calls to kReinitializeHandle() do not result in repeatedly
// adding new listeners on the socket (i.e. no MaxListenersExceededWarnings)

process.on('warning', common.mustNotCall());

const server = tls.createServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
});

server.listen(0, common.mustCall(function() {
const socket = tls.connect({
port: this.address().port,
rejectUnauthorized: false
});

socket.on('secureConnect', common.mustCall(function() {
for (let i = 0; i < events.defaultMaxListeners + 1; i++) {
socket[kReinitializeHandle]();
}

socket.destroy();
}));

socket.on('close', function() {
server.close();
});
}));

0 comments on commit f531d15

Please sign in to comment.