Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Cluster: fix shared handles on Windows
Browse files Browse the repository at this point in the history
This is the Node side of the fix for Node's cluster module on Windows.
#7691

The other required part is
joyent/libuv#1384

Windows and Unix return certain socket errors (i.e. EADDRINUSE) at
different times: bind on Windows, and listen on Unix.
In an effort to hide this difference, libuv on Windows stores such
errors in the bind_error field of uv_tcp_t, to defer raising it at
listen time.
This worked fine except for the case in which a socket is shared in
a Node cluster and a bind error occurs.

A previous attempt to fix this (
joyent/libuv@d1e6be1
3da36fe
) was flawed becaused in an attempt to relay the error at the JS level
it caused the master to start accepting connections.

With this new approach, libuv itself is relaying the bind errors,
providing for a uniform behavior of uv_tcp_listen.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
orangemocha authored and indutny committed Aug 7, 2014
1 parent e49429e commit 7ca4fa5
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,17 +1089,6 @@ var createServerHandle = exports._createServerHandle =
return err;
}

if (process.platform === 'win32') {
// On Windows, we always listen to the socket before sending it to
// the worker (see uv_tcp_duplicate_socket). So we better do it here
// so that we can handle any bind-time or listen-time errors early.
err = _listen(handle);
if (err) {
handle.close();
return err;
}
}

return handle;
};

Expand All @@ -1108,8 +1097,6 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
debug('listen2', address, port, addressType, backlog);
var self = this;

var alreadyListening = false;

// If there is not yet a handle, we need to create one and bind.
// In the case of a server sent via IPC, we don't need to do this.
if (!self._handle) {
Expand All @@ -1122,7 +1109,6 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
});
return;
}
alreadyListening = (process.platform === 'win32');
self._handle = rval;
} else {
debug('_listen2: have a handle already');
Expand All @@ -1131,9 +1117,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
self._handle.onconnection = onconnection;
self._handle.owner = self;

var err = 0;
if (!alreadyListening)
err = _listen(self._handle, backlog);
var err = _listen(self._handle, backlog);

if (err) {
var ex = errnoException(err, 'listen');
Expand Down

0 comments on commit 7ca4fa5

Please sign in to comment.