GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tls: reduce TLS 'close' event listener warnings · nodejs/node@ce27ee7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _tls_wrap.js
  • test/parallel
    • test-tls-reinitialize-listeners.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,12 @@ TLSSocket.prototype._wrapHandle = function(wrap, handle, wrapHasActiveWriteFromP
713713
this[kRes] = res;
714714
defineHandleReading(this, handle);
715715

716-
this.on('close', onSocketCloseDestroySSL);
716+
// Guard against adding multiple listeners, as this method may be called
717+
// repeatedly on the same socket by reinitializeHandle
718+
if (this.listenerCount('close', onSocketCloseDestroySSL) === 0) {
719+
this.on('close', onSocketCloseDestroySSL);
720+
}
721+
717722
if (wrap) {
718723
wrap.on('close', () => this.destroy());
719724
}
Collapse file

‎test/parallel/test-tls-reinitialize-listeners.js‎

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
if (!common.hasCrypto) {
7+
common.skip('missing crypto');
8+
}
9+
10+
const events = require('events');
11+
const fixtures = require('../common/fixtures');
12+
const tls = require('tls');
13+
const { kReinitializeHandle } = require('internal/net');
14+
15+
// Test that repeated calls to kReinitializeHandle() do not result in repeatedly
16+
// adding new listeners on the socket (i.e. no MaxListenersExceededWarnings)
17+
18+
process.on('warning', common.mustNotCall());
19+
20+
const server = tls.createServer({
21+
key: fixtures.readKey('agent1-key.pem'),
22+
cert: fixtures.readKey('agent1-cert.pem')
23+
});
24+
25+
server.listen(0, common.mustCall(function() {
26+
const socket = tls.connect({
27+
port: this.address().port,
28+
rejectUnauthorized: false
29+
});
30+
31+
socket.on('secureConnect', common.mustCall(function() {
32+
for (let i = 0; i < events.defaultMaxListeners + 1; i++) {
33+
socket[kReinitializeHandle]();
34+
}
35+
36+
socket.destroy();
37+
}));
38+
39+
socket.on('close', function() {
40+
server.close();
41+
});
42+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.