diff --git a/doc/api/net.md b/doc/api/net.md index 35e7abcee85cad..8e40c2297df77a 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -121,6 +121,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 9cd648953eb25b..c819ac1516ebef 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1487,7 +1487,8 @@ Server.prototype.getConnections = function(cb) { } if (!this._usingSlaves) { - return end(null, this._connections); + end(null, this._connections); + return this; } // Poll slaves @@ -1507,6 +1508,8 @@ Server.prototype.getConnections = function(cb) { this._slaves.forEach(function(slave) { slave.getConnections(oncount); }); + + return this; }; diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index b2f756c1ba7147..1bcf5992124342 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -16,10 +16,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;