mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
dc04c5ed9a
Without this, some heavy usage of TLS sockets can result in MaxListenersExceededWarning firing, from the 'this.on('close', ...)' line here. These appear to come from reinitializeHandle, which calls _wrapHandle repeatedly on the same socket instance. PR-URL: https://github.com/nodejs/node/pull/50136 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
// 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();
|
|
});
|
|
}));
|