diff --git a/doc/api/net.md b/doc/api/net.md index 86c9159bcfbcab..c66b87a261152b 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -162,6 +162,8 @@ connections use asynchronous `server.getConnections` instead. added: v0.9.7 --> +* Returns {net.Server} + Asynchronously get the number of concurrent connections on the server. Works when sockets were sent to forks. diff --git a/lib/net.js b/lib/net.js index 19f69aaaad73b8..278153d3bdffc7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1558,7 +1558,8 @@ Server.prototype.getConnections = function(cb) { } if (!this._usingSlaves) { - return end(null, this._connections); + end(null, this._connections); + return this; } // Poll slaves @@ -1578,6 +1579,8 @@ Server.prototype.getConnections = function(cb) { for (var n = 0; n < this._slaves.length; n++) { this._slaves[n].getConnections(oncount); } + + return this; }; diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index d030d069c6d1d7..c83cfaf94349df 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -37,10 +37,13 @@ function pingPongTest(port, host) { function onSocket(socket) { assert.strictEqual(socket.server, server); - server.getConnections(common.mustCall(function(err, connections) { - assert.ifError(err); - assert.strictEqual(connections, 1); - })); + assert.strictEqual( + server, + server.getConnections(common.mustCall(function(err, connections) { + assert.ifError(err); + assert.strictEqual(connections, 1); + })) + ); socket.setNoDelay(); socket.timeout = 0;