Skip to content

Commit

Permalink
net: remove long deprecated server.connections property
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>

PR-URL: #33647
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell committed Jun 1, 2020
1 parent a85ce88 commit 41796eb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 195 deletions.
5 changes: 2 additions & 3 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1379,9 +1379,8 @@ process.on('message', (m, socket) => {
```

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

It is also recommended that any `'message'` handlers in the child process
verify that `socket` exists, as the connection may have been closed during the
Expand Down
10 changes: 6 additions & 4 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ This behavior has been removed.
### DEP0020: `Server.connections`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33647
description: Server.connections has been removed.
- version:
- v4.8.6
- v6.12.0
Expand All @@ -491,10 +494,10 @@ changes:
description: Runtime deprecation.
-->

Type: Runtime
Type: End-of-life

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

<a id="DEP0021"></a>
### DEP0021: `Server.listenFD`
Expand Down Expand Up @@ -2759,7 +2762,6 @@ const moduleParents = Object.values(require.cache)
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname
[`REPLServer.clearBufferedCommand()`]: repl.html#repl_replserver_clearbufferedcommand
[`ReadStream.open()`]: fs.html#fs_class_fs_readstream
[`Server.connections`]: net.html#net_server_connections
[`Server.getConnections()`]: net.html#net_server_getconnections_callback
[`Server.listen({fd: <number>})`]: net.html#net_server_listen_handle_backlog_callback
[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer
Expand Down
17 changes: 0 additions & 17 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,6 @@ The optional `callback` will be called once the `'close'` event occurs. Unlike
that event, it will be called with an `Error` as its only argument if the server
was not open when it was closed.

### `server.connections`
<!-- YAML
added: v0.2.0
deprecated: v0.9.7
-->

> Stability: 0 - Deprecated: Use [`server.getConnections()`][] instead.
* {integer|null}

The number of concurrent connections on the server.

This becomes `null` when sending a socket to a child with
[`child_process.fork()`][]. To poll forks and get current number of active
connections, use asynchronous [`server.getConnections()`][] instead.

### `server.getConnections(callback)`
<!-- YAML
added: v0.9.7
Expand Down Expand Up @@ -1256,7 +1240,6 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
[`new net.Socket(options)`]: #net_new_net_socket_options
[`readable.setEncoding()`]: stream.html#stream_readable_setencoding_encoding
[`server.close()`]: #net_server_close_callback
[`server.getConnections()`]: #net_server_getconnections_callback
[`server.listen()`]: #net_server_listen
[`server.listen(handle)`]: #net_server_listen_handle_backlog_callback
[`server.listen(options)`]: #net_server_listen_options_callback
Expand Down
13 changes: 0 additions & 13 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,6 @@ The `server.close()` method stops the server from accepting new connections.
This function operates asynchronously. The `'close'` event will be emitted
when the server has no more open connections.

### `server.connections`
<!-- YAML
added: v0.3.2
deprecated: v0.9.7
-->

> Stability: 0 - Deprecated: Use [`server.getConnections()`][] instead.
* {number}

Returns the current number of concurrent connections on the server.

### `server.getTicketKeys()`
<!-- YAML
added: v3.0.0
Expand Down Expand Up @@ -1963,7 +1951,6 @@ where `secureSocket` has the same API as `pair.cleartext`.
[`net.Server`]: net.html#net_class_net_server
[`net.Socket`]: net.html#net_class_net_socket
[`server.addContext()`]: #tls_server_addcontext_hostname_context
[`server.getConnections()`]: net.html#net_server_getconnections_callback
[`server.getTicketKeys()`]: #tls_server_getticketkeys
[`server.listen()`]: net.html#net_server_listen
[`server.setTicketKeys()`]: #tls_server_setticketkeys_keys
Expand Down
16 changes: 0 additions & 16 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const { inspect } = require('internal/util/inspect');
let debug = require('internal/util/debuglog').debuglog('net', (fn) => {
debug = fn;
});
const { deprecate } = require('internal/util');
const {
isIP,
isIPv4,
Expand Down Expand Up @@ -1157,21 +1156,6 @@ function Server(options, connectionListener) {

this._connections = 0;

ObjectDefineProperty(this, 'connections', {
get: deprecate(() => {

if (this._usingWorkers) {
return null;
}
return this._connections;
}, 'Server.connections property is deprecated. ' +
'Use Server.getConnections method instead.', 'DEP0020'),
set: deprecate((val) => (this._connections = val),
'Server.connections property is deprecated.',
'DEP0020'),
configurable: true, enumerable: false
});

this[async_id_symbol] = -1;
this._handle = null;
this._usingWorkers = false;
Expand Down
28 changes: 7 additions & 21 deletions test/parallel/test-net-server-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,26 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const net = require('net');

const events = [];
const sockets = [];

process.on('exit', function() {
assert.strictEqual(server.connections, 0);
assert.strictEqual(events.length, 3);
// Expect to see one server event and two client events. The order of the
// events is undefined because they arrive on the same event loop tick.
assert.strictEqual(events.join(' ').match(/server/g).length, 1);
assert.strictEqual(events.join(' ').match(/client/g).length, 2);
});

const server = net.createServer(function(c) {
c.on('close', function() {
events.push('client');
});
c.on('close', common.mustCall());

sockets.push(c);

if (sockets.length === 2) {
assert.strictEqual(server.close(), server);
sockets.forEach(function(c) { c.destroy(); });
sockets.forEach((c) => c.destroy());
}
});

server.on('close', function() {
events.push('server');
});
server.on('close', common.mustCall());

assert.strictEqual(server, server.listen(0, function() {
net.createConnection(this.address().port);
net.createConnection(this.address().port);
assert.strictEqual(server, server.listen(0, () => {
net.createConnection(server.address().port);
net.createConnection(server.address().port);
}));
46 changes: 0 additions & 46 deletions test/parallel/test-net-server-connections-child-null.js

This file was deleted.

39 changes: 0 additions & 39 deletions test/parallel/test-net-server-connections.js

This file was deleted.

28 changes: 3 additions & 25 deletions test/parallel/test-net-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,19 @@

'use strict';

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

const s = new net.Stream();

// Test that destroy called on a stream with a server only ever decrements the
// server connection count once

s.server = new net.Server();
s.server.connections = 10;
s._server = s.server;

assert.strictEqual(s.server.connections, 10);
s.destroy();
assert.strictEqual(s.server.connections, 9);
s.destroy();
assert.strictEqual(s.server.connections, 9);

const SIZE = 2E6;
const N = 10;
const buf = Buffer.alloc(SIZE, 'a');

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

socket.on('error', function(err) {
socket.destroy();
}).on('close', function() {
server.close();
});
socket.on('error', common.mustCall(() => socket.destroy()))
.on('close', common.mustCall(() => server.close()));

for (let i = 0; i < N; ++i) {
socket.write(buf, () => {});
Expand All @@ -67,7 +49,3 @@ const server = net.createServer(function(socket) {
}, 20);
});
});

process.on('exit', function() {
assert.strictEqual(server.connections, 0);
});
14 changes: 3 additions & 11 deletions test/parallel/test-net-sync-cork.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

Expand All @@ -26,16 +26,8 @@ server.listen(0, function() {
});
});

process.on('exit', function() {
assert.strictEqual(server.connections, 0);
});

function handle(socket) {
socket.resume();

socket.on('error', function(err) {
socket.destroy();
}).on('close', function() {
server.close();
});
socket.on('error', common.mustNotCall())
.on('close', common.mustCall(() => server.close()));
}

0 comments on commit 41796eb

Please sign in to comment.