Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: refactor onSlaveClose in Server.close #12334

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,13 +1539,6 @@ Server.prototype.getConnections = function(cb) {


Server.prototype.close = function(cb) {
function onSlaveClose() {
if (--left !== 0) return;

self._connections = 0;
self._emitCloseIfDrained();
}

if (typeof cb === 'function') {
if (!this._handle) {
this.once('close', function close() {
Expand All @@ -1562,8 +1555,13 @@ Server.prototype.close = function(cb) {
}

if (this._usingSlaves) {
var self = this;
var left = this._slaves.length;
const onSlaveClose = () => {
if (--left !== 0) return;

this._connections = 0;
this._emitCloseIfDrained();
};

// Increment connections to be sure that, even if all sockets will be closed
// during polling of slaves, `close` event will be emitted only once.
Expand Down