Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

windows: relay TCP bind errors via ipc #1384

Merged
merged 1 commit into from
Jul 31, 2014
Merged

windows: relay TCP bind errors via ipc #1384

merged 1 commit into from
Jul 31, 2014

Conversation

orangemocha
Copy link

This is the libuv side of the fix for Node's cluster module on Windows.
nodejs/node-v0.x-archive#7691

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 (
d1e6be1
nodejs/node-v0.x-archive@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.

@saghul
Copy link
Contributor

saghul commented Jul 29, 2014

Can we have a libuv test case for this?

@orangemocha
Copy link
Author

cc @piscisaureus

typedef struct {
WSAPROTOCOL_INFOW socket_info;
int bind_error;
} uv_ipc_socket_info_ex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it uv__ipc_socket_info_ex as it's an internal thing and we lean towards that naming.

orangemocha added a commit to nodejs/node-v0.x-archive that referenced this pull request Jul 31, 2014
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 <[email protected]>
@orangemocha
Copy link
Author

Added test case (win32-only), and cleaned up per your suggestions. Thanks!

@@ -205,6 +204,70 @@ static void on_read(uv_stream_t* handle,
free(buf->base);
}

#ifdef _WIN32
static void on_read_listen_after_bound_twice(uv_stream_t* handle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: align arguments with the first one.

@saghul
Copy link
Contributor

saghul commented Jul 31, 2014

Some style nits, otherwise LGTM. I'll run tests later.

This is the libuv side of the fix for Node's cluster module on Windows.
nodejs/node-v0.x-archive#7691

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 (
d1e6be1
nodejs/node-v0.x-archive@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.
@orangemocha
Copy link
Author

Amended to address your latest feedback. Thanks!

@saghul saghul merged commit 6d3a051 into joyent:master Jul 31, 2014
@saghul
Copy link
Contributor

saghul commented Jul 31, 2014

Thanks Alexis! Extra karma for refactoring the bind_error attribute :-) 👍

orangemocha added a commit to nodejs/node-v0.x-archive that referenced this pull request Aug 7, 2014
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 <[email protected]>
fdgonthier pushed a commit to opersys/node that referenced this pull request Apr 1, 2015
This is the Node side of the fix for Node's cluster module on Windows.
nodejs/node-v0.x-archive#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
nodejs/node-v0.x-archive@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 <[email protected]>
fdgonthier pushed a commit to opersys/node that referenced this pull request Apr 1, 2015
This is the Node side of the fix for Node's cluster module on Windows.
nodejs/node-v0.x-archive#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
nodejs/node-v0.x-archive@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 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants