diff options
-rw-r--r-- | doc/api/child_process.md | 5 | ||||
-rw-r--r-- | doc/api/deprecations.md | 10 | ||||
-rw-r--r-- | doc/api/net.md | 17 | ||||
-rw-r--r-- | doc/api/tls.md | 13 | ||||
-rw-r--r-- | lib/net.js | 16 | ||||
-rw-r--r-- | test/parallel/test-net-server-close.js | 28 | ||||
-rw-r--r-- | test/parallel/test-net-server-connections-child-null.js | 46 | ||||
-rw-r--r-- | test/parallel/test-net-server-connections.js | 39 | ||||
-rw-r--r-- | test/parallel/test-net-stream.js | 28 | ||||
-rw-r--r-- | test/parallel/test-net-sync-cork.js | 14 |
10 files changed, 21 insertions, 195 deletions
diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 5657f2014a..2f18567737 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -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 diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5df161c1c6..1ee93d055b 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -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 @@ -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` @@ -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 diff --git a/doc/api/net.md b/doc/api/net.md index 3e16d4a638..89b3de2f3b 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -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 @@ -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 diff --git a/doc/api/tls.md b/doc/api/tls.md index 7df3f0a511..bfebf5cc26 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -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 @@ -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 diff --git a/lib/net.js b/lib/net.js index 352a1d0e99..c92381f56d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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, @@ -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; diff --git a/test/parallel/test-net-server-close.js b/test/parallel/test-net-server-close.js index 89bfddd38a..8291f70432 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -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); })); diff --git a/test/parallel/test-net-server-connections-child-null.js b/test/parallel/test-net-server-connections-child-null.js deleted file mode 100644 index bf75826fdd..0000000000 --- a/test/parallel/test-net-server-connections-child-null.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const fork = require('child_process').fork; -const net = require('net'); - -if (process.argv[2] === 'child') { - - process.on('message', (msg, socket) => { - socket.end('goodbye'); - }); - - process.send('hello'); - -} else { - - const child = fork(process.argv[1], ['child']); - - const runTest = common.mustCall(() => { - - const server = net.createServer(); - - // server.connections should start as 0 - assert.strictEqual(server.connections, 0); - server.on('connection', (socket) => { - child.send({ what: 'socket' }, socket); - }); - server.on('close', () => { - child.kill(); - }); - - server.listen(0, common.mustCall(() => { - const connect = net.connect(server.address().port); - - connect.on('close', common.mustCall(() => { - // `server.connections` should now be null. - assert.strictEqual(server.connections, null); - server.close(); - })); - - connect.resume(); - })); - }); - - child.on('message', runTest); -} diff --git a/test/parallel/test-net-server-connections.js b/test/parallel/test-net-server-connections.js deleted file mode 100644 index 52b2fe6bf5..0000000000 --- a/test/parallel/test-net-server-connections.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); - -const net = require('net'); - -const server = new net.Server(); - -const expectedWarning = 'Server.connections property is deprecated. ' + - 'Use Server.getConnections method instead.'; - -common.expectWarning('DeprecationWarning', expectedWarning, 'DEP0020'); - -// Test that server.connections property is no longer enumerable now that it -// has been marked as deprecated -assert.strictEqual(Object.keys(server).includes('connections'), false); - -assert.strictEqual(server.connections, 0); diff --git a/test/parallel/test-net-stream.js b/test/parallel/test-net-stream.js index 8e996dd58a..454dc69038 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -21,25 +21,10 @@ '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'); @@ -47,11 +32,8 @@ 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, () => {}); @@ -67,7 +49,3 @@ const server = net.createServer(function(socket) { }, 20); }); }); - -process.on('exit', function() { - assert.strictEqual(server.connections, 0); -}); diff --git a/test/parallel/test-net-sync-cork.js b/test/parallel/test-net-sync-cork.js index 3872f5f969..447f42ca91 100644 --- a/test/parallel/test-net-sync-cork.js +++ b/test/parallel/test-net-sync-cork.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); @@ -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())); } |