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

Unable to use reuseport with gen_udp:open #7569

Closed
LVala opened this issue Aug 17, 2023 · 2 comments · Fixed by #7587
Closed

Unable to use reuseport with gen_udp:open #7569

LVala opened this issue Aug 17, 2023 · 2 comments · Fixed by #7587
Assignees
Labels
bug Issue is reported as a bug in progress priority:medium team:PS Assigned to OTP team PS

Comments

@LVala
Copy link

LVala commented Aug 17, 2023

Describe the bug
Documentation suggests that from OTP 26, inet:setopts allows to set the reuseport. When trying to set the option with gen_udp:open, I get the following error:

Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Eshell V14.0.2 (press Ctrl+G to abort, type help(). for help)
1> gen_udp:open(55001, [{reuseport, true}]).
** exception exit: badarg
     in function  inet_udp:open/2 (inet_udp.erl, line 56)

After looking at otp/lib/kernel/src/inet.erl I noticed that function udp_options doesn't list reuseport as an available option, which is not the case for e.g. listen_options and indeed, gen_tcp:listen works fine with the reuseport:

1> {ok, Socket} = gen_tcp:listen(55001, [{reuseport, true}]).
{ok,#Port<0.3>}

Getting back to UDP, the option can be set via inet:setopts, but that doesn't help, as the next opened socket need to use reuseport as well, which must be set before binding to address:

1> {ok, Socket} = gen_udp:open(55001).
{ok,#Port<0.3>}
2> ok = inet:setopts(Socket, [{reuseport, true}]).
ok
3> inet:getopts(Socket, [reuseport]).
{ok,[{reuseport,true}]}
4> {ok, Sock2} = gen_udp:open(55001).
** exception error: no match of right hand side value {error,eaddrinuse}

My workaround was to use socket module, which works as expected, but the above does not seem to be the desired behaviour.

To Reproduce
Run gen_udp:open(55001, [{reuseport, true}])..

Expected behavior
I expect to be able to use reuseport option when opening UDP socket via gen_udp:open.

Affected versions
OTP 26.0.2
MacOS M1

$ sysctl kern.version
kern.version: Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000

Additional context
None.

@LVala LVala added the bug Issue is reported as a bug label Aug 17, 2023
@IngelaAndin IngelaAndin added the team:PS Assigned to OTP team PS label Aug 18, 2023
@RaimoNiskanen
Copy link
Contributor

This seems to be a bug in PR #6522 that missed to allow the new options for gen_udp:open/1,2.
I'll start on a fix.

@RaimoNiskanen RaimoNiskanen self-assigned this Aug 23, 2023
@RaimoNiskanen RaimoNiskanen linked a pull request Aug 23, 2023 that will close this issue
RaimoNiskanen added a commit that referenced this issue Sep 4, 2023
…to maint

* raimo/kernel/gen_udp-pass-options/GH-7569/OTP-18734:
  'dontroute' does not work on all platforms
  Test more UDP socket options
  Test UDP socket options
  Allow missing options in open() calls
@RaimoNiskanen
Copy link
Contributor

Fix merged to 'maint' to be released in OTP-26.1.
Thank you for reporting this issue!

max-au added a commit to max-au/otp that referenced this issue Oct 31, 2023
Typo introduced in erlang#7569 may may cause pg to crash when 'DOWN'
monitor message is in the queue while explicit leave is processed earlier.

Closes erlang#7807
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 priority:medium team:PS Assigned to OTP team PS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants