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

gen_udp:open/2 does not set {reuseaddr, true} on Windows 10 #4819

Closed
ziopio opened this issue May 11, 2021 · 11 comments
Closed

gen_udp:open/2 does not set {reuseaddr, true} on Windows 10 #4819

ziopio opened this issue May 11, 2021 · 11 comments
Assignees
Labels
bug Issue is reported as a bug in progress team:PS Assigned to OTP team PS

Comments

@ziopio
Copy link
Contributor

ziopio commented May 11, 2021

Describe the bug
On Windows 10 64-bit, when i try to open an UDP port with option {reuseaddr, true} the option is not applied.
The resulting socket owns the port exclusively. This makes it impossible to open multiple sockets on the same port.
The bug DOES NOT occur on an OTP linux installation executing through WSL.

To Reproduce (OTP 23.3 Eshell V11.2, Windows 10 64-bit )
1> {_,S} = gen_udp:open(0,[{reuseaddr, true}]).
{ok,#Port<0.4>}
2> inet:getopts(S,[reuseaddr]).
{ok,[{reuseaddr,false}]}

Expected behavior (OTP 22 Eshell V10.6.4, Ubuntu 20.04 on WSL )
1> {_,S} = gen_udp:open(0,[{reuseaddr, true}]).
{ok,#Port<0.4>}
2> inet:getopts(S,[reuseaddr]).
{ok,[{reuseaddr,true}]}

Affected versions
Erlang/OTP 23.3 with Eshell V 11.2, 64-bit binary installation on Windows 10

Additional context
I my case i am implementing the RTPS protocol by ObjectManagmentGroup in Erlang. The p2p discovery requires multiple participants to listen to the same port for UDP multicast packets. This bug prevents me to start more than one node on my system.

@ziopio ziopio added the bug Issue is reported as a bug label May 11, 2021
@bmk
Copy link
Contributor

bmk commented May 12, 2021

After some searching on the net, I found that this (REUSEADDR) seems to have issues on windows.
For instance Apache HTTPD only use it on non-windows.

I also found the following comment:

"I understand REUSE is popular under *nix because it prevents re-binding process restart errors
for processes stuck in TIME_WAIT.
Supposedly Windows does not have this issue of preventing socket binding for socket addr/port combinations in TIME_WAIT.
Apparently there is little value to using REUSE under Windows except in cases where you are using multicast."

@rickard-green rickard-green added the team:PS Assigned to OTP team PS label May 15, 2021
@juhlig
Copy link
Contributor

juhlig commented May 25, 2021

The same applies to gen_tcp etc. From inet_drv.c, with my favorite explanatory comment of all times 😁:

case INET_OPT_REUSEADDR:
#ifdef __WIN32__
continue; /* Bjorn says */

@ziopio
Copy link
Contributor Author

ziopio commented May 25, 2021

So... it's more like an intended feature then a bug😅

@bmk
Copy link
Contributor

bmk commented May 25, 2021

I think it should be "feature" in this case...

@Maria-12648430
Copy link
Contributor

"Bjorn says", priceless 😄

@juhlig
Copy link
Contributor

juhlig commented May 25, 2021

I think it should be "feature" in this case...

I don't remember all the details, but IIRC reuseaddr means something very different (and dangerous, of course) on Windows...

@juhlig
Copy link
Contributor

juhlig commented May 26, 2021

@bjorng
Copy link
Contributor

bjorng commented May 26, 2021 via email

@bmk bmk linked a pull request Jun 3, 2021 that will close this issue
@bmk
Copy link
Contributor

bmk commented Jun 3, 2021

Added a PR, which solves this by introducing a new option; 'win_reuseaddr' which
functions the "same way" as 'reuseaddr' but reversed. That is, it is ignored on all
non-Windows.

@bmk
Copy link
Contributor

bmk commented Dec 22, 2021

This option, 'reuseaddr', will be handled the same way on Windows as on other OSes. As of 25.0!

@rickard-green
Copy link
Contributor

@ziopio As of OTP 26 the reuseaddr option will revert back to how it behaved prior to OTP 25 on Windows. The reuseport option will however be added in OTP 26, so you will be able to do what you want by passing the [{reuseaddr,true},{reuseport,true}] options on Windows in order to do what you want. For more information see the #6522 pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug in progress team:PS Assigned to OTP team PS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants