Skip to content

Commit 41796eb

Browse files
committed
net: remove long deprecated server.connections property
The server.connections property was runtime deprecated in the 0.9 days. It was replaced with getConnections(). It is not simply an alias for getConnections() because it fails to take connections shared with forks into consideration. Let's not keep it around forever and move it to end of life Signed-off-by: James M Snell <[email protected]> PR-URL: #33647 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent a85ce88 commit 41796eb

10 files changed

+21
-195
lines changed

Diff for: doc/api/child_process.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1379,9 +1379,8 @@ process.on('message', (m, socket) => {
13791379
```
13801380

13811381
Once a socket has been passed to a child, the parent is no longer capable of
1382-
tracking when the socket is destroyed. To indicate this, the `.connections`
1383-
property becomes `null`. It is recommended not to use `.maxConnections` when
1384-
this occurs.
1382+
tracking when the socket is destroyed. It is recommended not to use
1383+
`.maxConnections` when this occurs.
13851384

13861385
It is also recommended that any `'message'` handlers in the child process
13871386
verify that `socket` exists, as the connection may have been closed during the

Diff for: doc/api/deprecations.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ This behavior has been removed.
481481
### DEP0020: `Server.connections`
482482
<!-- YAML
483483
changes:
484+
- version: REPLACEME
485+
pr-url: https://github.com/nodejs/node/pull/33647
486+
description: Server.connections has been removed.
484487
- version:
485488
- v4.8.6
486489
- v6.12.0
@@ -491,10 +494,10 @@ changes:
491494
description: Runtime deprecation.
492495
-->
493496

494-
Type: Runtime
497+
Type: End-of-life
495498

496-
The [`Server.connections`][] property is deprecated. Please use the
497-
[`Server.getConnections()`][] method instead.
499+
The `Server.connections` property was deprecated in Node.js v0.9.7 and has
500+
been removed. Please use the [`Server.getConnections()`][] method instead.
498501

499502
<a id="DEP0021"></a>
500503
### DEP0021: `Server.listenFD`
@@ -2759,7 +2762,6 @@ const moduleParents = Object.values(require.cache)
27592762
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname
27602763
[`REPLServer.clearBufferedCommand()`]: repl.html#repl_replserver_clearbufferedcommand
27612764
[`ReadStream.open()`]: fs.html#fs_class_fs_readstream
2762-
[`Server.connections`]: net.html#net_server_connections
27632765
[`Server.getConnections()`]: net.html#net_server_getconnections_callback
27642766
[`Server.listen({fd: <number>})`]: net.html#net_server_listen_handle_backlog_callback
27652767
[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer

Diff for: doc/api/net.md

-17
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@ The optional `callback` will be called once the `'close'` event occurs. Unlike
156156
that event, it will be called with an `Error` as its only argument if the server
157157
was not open when it was closed.
158158

159-
### `server.connections`
160-
<!-- YAML
161-
added: v0.2.0
162-
deprecated: v0.9.7
163-
-->
164-
165-
> Stability: 0 - Deprecated: Use [`server.getConnections()`][] instead.
166-
167-
* {integer|null}
168-
169-
The number of concurrent connections on the server.
170-
171-
This becomes `null` when sending a socket to a child with
172-
[`child_process.fork()`][]. To poll forks and get current number of active
173-
connections, use asynchronous [`server.getConnections()`][] instead.
174-
175159
### `server.getConnections(callback)`
176160
<!-- YAML
177161
added: v0.9.7
@@ -1256,7 +1240,6 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
12561240
[`new net.Socket(options)`]: #net_new_net_socket_options
12571241
[`readable.setEncoding()`]: stream.html#stream_readable_setencoding_encoding
12581242
[`server.close()`]: #net_server_close_callback
1259-
[`server.getConnections()`]: #net_server_getconnections_callback
12601243
[`server.listen()`]: #net_server_listen
12611244
[`server.listen(handle)`]: #net_server_listen_handle_backlog_callback
12621245
[`server.listen(options)`]: #net_server_listen_options_callback

Diff for: doc/api/tls.md

-13
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,6 @@ The `server.close()` method stops the server from accepting new connections.
580580
This function operates asynchronously. The `'close'` event will be emitted
581581
when the server has no more open connections.
582582

583-
### `server.connections`
584-
<!-- YAML
585-
added: v0.3.2
586-
deprecated: v0.9.7
587-
-->
588-
589-
> Stability: 0 - Deprecated: Use [`server.getConnections()`][] instead.
590-
591-
* {number}
592-
593-
Returns the current number of concurrent connections on the server.
594-
595583
### `server.getTicketKeys()`
596584
<!-- YAML
597585
added: v3.0.0
@@ -1963,7 +1951,6 @@ where `secureSocket` has the same API as `pair.cleartext`.
19631951
[`net.Server`]: net.html#net_class_net_server
19641952
[`net.Socket`]: net.html#net_class_net_socket
19651953
[`server.addContext()`]: #tls_server_addcontext_hostname_context
1966-
[`server.getConnections()`]: net.html#net_server_getconnections_callback
19671954
[`server.getTicketKeys()`]: #tls_server_getticketkeys
19681955
[`server.listen()`]: net.html#net_server_listen
19691956
[`server.setTicketKeys()`]: #tls_server_setticketkeys_keys

Diff for: lib/net.js

-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const { inspect } = require('internal/util/inspect');
3838
let debug = require('internal/util/debuglog').debuglog('net', (fn) => {
3939
debug = fn;
4040
});
41-
const { deprecate } = require('internal/util');
4241
const {
4342
isIP,
4443
isIPv4,
@@ -1157,21 +1156,6 @@ function Server(options, connectionListener) {
11571156

11581157
this._connections = 0;
11591158

1160-
ObjectDefineProperty(this, 'connections', {
1161-
get: deprecate(() => {
1162-
1163-
if (this._usingWorkers) {
1164-
return null;
1165-
}
1166-
return this._connections;
1167-
}, 'Server.connections property is deprecated. ' +
1168-
'Use Server.getConnections method instead.', 'DEP0020'),
1169-
set: deprecate((val) => (this._connections = val),
1170-
'Server.connections property is deprecated.',
1171-
'DEP0020'),
1172-
configurable: true, enumerable: false
1173-
});
1174-
11751159
this[async_id_symbol] = -1;
11761160
this._handle = null;
11771161
this._usingWorkers = false;

Diff for: test/parallel/test-net-server-close.js

+7-21
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,26 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const net = require('net');
2626

27-
const events = [];
2827
const sockets = [];
2928

30-
process.on('exit', function() {
31-
assert.strictEqual(server.connections, 0);
32-
assert.strictEqual(events.length, 3);
33-
// Expect to see one server event and two client events. The order of the
34-
// events is undefined because they arrive on the same event loop tick.
35-
assert.strictEqual(events.join(' ').match(/server/g).length, 1);
36-
assert.strictEqual(events.join(' ').match(/client/g).length, 2);
37-
});
38-
3929
const server = net.createServer(function(c) {
40-
c.on('close', function() {
41-
events.push('client');
42-
});
30+
c.on('close', common.mustCall());
4331

4432
sockets.push(c);
4533

4634
if (sockets.length === 2) {
4735
assert.strictEqual(server.close(), server);
48-
sockets.forEach(function(c) { c.destroy(); });
36+
sockets.forEach((c) => c.destroy());
4937
}
5038
});
5139

52-
server.on('close', function() {
53-
events.push('server');
54-
});
40+
server.on('close', common.mustCall());
5541

56-
assert.strictEqual(server, server.listen(0, function() {
57-
net.createConnection(this.address().port);
58-
net.createConnection(this.address().port);
42+
assert.strictEqual(server, server.listen(0, () => {
43+
net.createConnection(server.address().port);
44+
net.createConnection(server.address().port);
5945
}));

Diff for: test/parallel/test-net-server-connections-child-null.js

-46
This file was deleted.

Diff for: test/parallel/test-net-server-connections.js

-39
This file was deleted.

Diff for: test/parallel/test-net-stream.js

+3-25
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,19 @@
2121

2222
'use strict';
2323

24-
require('../common');
24+
const common = require('../common');
2525
const assert = require('assert');
2626
const net = require('net');
2727

28-
const s = new net.Stream();
29-
30-
// Test that destroy called on a stream with a server only ever decrements the
31-
// server connection count once
32-
33-
s.server = new net.Server();
34-
s.server.connections = 10;
35-
s._server = s.server;
36-
37-
assert.strictEqual(s.server.connections, 10);
38-
s.destroy();
39-
assert.strictEqual(s.server.connections, 9);
40-
s.destroy();
41-
assert.strictEqual(s.server.connections, 9);
42-
4328
const SIZE = 2E6;
4429
const N = 10;
4530
const buf = Buffer.alloc(SIZE, 'a');
4631

4732
const server = net.createServer(function(socket) {
4833
socket.setNoDelay();
4934

50-
socket.on('error', function(err) {
51-
socket.destroy();
52-
}).on('close', function() {
53-
server.close();
54-
});
35+
socket.on('error', common.mustCall(() => socket.destroy()))
36+
.on('close', common.mustCall(() => server.close()));
5537

5638
for (let i = 0; i < N; ++i) {
5739
socket.write(buf, () => {});
@@ -67,7 +49,3 @@ const server = net.createServer(function(socket) {
6749
}, 20);
6850
});
6951
});
70-
71-
process.on('exit', function() {
72-
assert.strictEqual(server.connections, 0);
73-
});

Diff for: test/parallel/test-net-sync-cork.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const net = require('net');
66

@@ -26,16 +26,8 @@ server.listen(0, function() {
2626
});
2727
});
2828

29-
process.on('exit', function() {
30-
assert.strictEqual(server.connections, 0);
31-
});
32-
3329
function handle(socket) {
3430
socket.resume();
35-
36-
socket.on('error', function(err) {
37-
socket.destroy();
38-
}).on('close', function() {
39-
server.close();
40-
});
31+
socket.on('error', common.mustNotCall())
32+
.on('close', common.mustCall(() => server.close()));
4133
}

0 commit comments

Comments
 (0)