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

using gen_tcp new interface inet_backend socket cann't listen multiple sockets in one port #319

Closed
dogtapdsd opened this issue Aug 14, 2021 · 6 comments
Milestone

Comments

@dogtapdsd
Copy link

dogtapdsd commented Aug 14, 2021

I try -kernel inet_backend socket options in erlang otp 24, follow the example from acceptor_SUITE:do_ssl_10_acceptors_10_listen_sockets/0, start listen 2 sockets from one port,it fail like this

=ERROR REPORT==== 14-Aug-2021::17:20:17.254374 ===
Failed to start Ranch listener cb_gen_tcp_listener in ranch_tcp:listen(#{connection_type => supervisor,max_connections => infinity,num_acceptors => 40,num_conns_sups => 40,num_listen_sockets => 2,socket_opts => [{cacerts,'...'},{key,'...'},{cert,'...'},{port,8000},{raw,1,15,<<1,0,0,0>>},{nodelay,false},{ip,any},{backlog,2048},{delay_send,false},{send_timeout,5000},{keepalive,true},{exit_on_close,true},{sndbuf,72000},{recbuf,12000}]}) for reason eaddrinuse (address already in use)

=SUPERVISOR REPORT==== 14-Aug-2021::17:20:17.266430 ===
supervisor: {<0.255.0>,ranch_listener_sup}
errorContext: start_error
reason: {listen_error,cb_gen_tcp_listener,eaddrinuse}
offender: [{pid,undefined},
{id,ranch_acceptors_sup},
{mfargs,
{ranch_acceptors_sup,start_link,
[cb_gen_tcp_listener,ranch_tcp,logger]}},
{restart_type,permanent},
{significant,false},
{shutdown,infinity},
{child_type,supervisor}]

=CRASH REPORT==== 14-Aug-2021::17:20:17.266517 ===
crasher:
initial call: supervisor:ranch_acceptors_sup/1
pid: <0.297.0>
registered_name: []
exception exit: {listen_error,cb_gen_tcp_listener,eaddrinuse}
in function ranch_acceptors_sup:listen_error/5 (src/ranch_acceptors_sup.erl, line 95)
in call from ranch_acceptors_sup:'-start_listen_sockets/5-lc$^0/1-0-'/5 (src/ranch_acceptors_sup.erl, line 70)
in call from ranch_acceptors_sup:start_listen_sockets/5 (src/ranch_acceptors_sup.erl, line 71)
in call from ranch_acceptors_sup:init/1 (src/ranch_acceptors_sup.erl, line 34)
in call from supervisor:init/1 (supervisor.erl, line 330)
in call from gen_server:init_it/2 (gen_server.erl, line 423)
in call from gen_server:init_it/6 (gen_server.erl, line 390)
ancestors: [<0.255.0>,ranch_sup,<0.120.0>]
message_queue_len: 0
messages: []
links: [<0.255.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 4185
stack_size: 29
reductions: 8783
neighbours:

inet:i().
Port Module Recv Sent Owner Local Address Foreign Address State Type
16 inet_tcp 0 0 <0.60.0> *:40001 : ACCEPTING STREAM
esock[18] gen_tcp_socket 6 27 <0.58.0> localhost:33328 localhost:epmd CD:SD STREAM
esock[41] gen_tcp_socket 13014 4216 <0.203.0> localhost:58544 localhost:mysql CD:SD STREAM
esock[40] gen_tcp_socket 12831 4219 <0.200.0> localhost:58540 localhost:mysql CD:SD STREAM
esock[39] gen_tcp_socket 12899 4199 <0.197.0> localhost:58538 localhost:mysql CD:SD STREAM
esock[38] gen_tcp_socket 12940 4224 <0.194.0> localhost:58536 localhost:mysql CD:SD STREAM
esock[37] gen_tcp_socket 12831 4276 <0.191.0> localhost:58534 localhost:mysql CD:SD STREAM
esock[36] gen_tcp_socket 12790 4299 <0.188.0> localhost:58532 localhost:mysql CD:SD STREAM
esock[35] gen_tcp_socket 14070 4402 <0.185.0> localhost:58530 localhost:mysql CD:SD STREAM
esock[34] gen_tcp_socket 12882 4238 <0.182.0> localhost:58528 localhost:mysql CD:SD STREAM
esock[33] gen_tcp_socket 12790 4249 <0.179.0> localhost:58526 localhost:mysql CD:SD STREAM
esock[32] gen_tcp_socket 12790 4246 <0.176.0> localhost:58524 localhost:mysql CD:SD STREAM
esock[31] gen_tcp_socket 12790 4278 <0.173.0> localhost:58522 localhost:mysql CD:SD STREAM
esock[30] gen_tcp_socket 12790 4250 <0.170.0> localhost:58520 localhost:mysql CD:SD STREAM
esock[29] gen_tcp_socket 12790 4278 <0.167.0> localhost:58518 localhost:mysql CD:SD STREAM
esock[28] gen_tcp_socket 12790 4244 <0.164.0> localhost:58516 localhost:mysql CD:SD STREAM
esock[27] gen_tcp_socket 12779 4185 <0.161.0> localhost:58514 localhost:mysql CD:SD STREAM
esock[26] gen_tcp_socket 12779 4185 <0.158.0> localhost:58512 localhost:mysql CD:SD STREAM
esock[25] gen_tcp_socket 12779 4185 <0.155.0> localhost:58510 localhost:mysql CD:SD STREAM
esock[24] gen_tcp_socket 12779 4185 <0.152.0> localhost:58508 localhost:mysql CD:SD STREAM
esock[22] gen_tcp_socket 12779 4185 <0.149.0> localhost:58506 localhost:mysql CD:SD STREAM
esock[21] gen_tcp_socket 12779 4185 <0.144.0> localhost:58504 localhost:mysql CD:SD STREAM

if change to old inet interface like “-kernel inet_backend inet”, That will work fine , Is any possible use this features with new socket nif API ?

@essen
Copy link
Member

essen commented Aug 14, 2021

Please try #297

@dogtapdsd
Copy link
Author

dogtapdsd commented Aug 16, 2021

Thanks, This is confuse me.
https://bugs.erlang.org/browse/ERL-1287
It say Fixed in 23.1 as OTP-16743.
but I when using otp 24 still get this error
eaddrinuse (address already in use)

@dogtapdsd
Copy link
Author

dogtapdsd commented Aug 16, 2021

ERL-1287 happen again In otp 24. so sad...

Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]
Eshell V12.0.3 (abort with ^G)
1>
1> gen_tcp:listen(0, [{inet_backend, socket}, {raw, 1, 15, <<1:32/native>>}, {port, 8888}, {ip, any}]).
{ok,{'$inet',gen_tcp_socket,
{<0.82.0>,
{'$socket',#Ref<0.1220593668.1297743873.200397>}}}}
2>
2> gen_tcp:listen(0, [{inet_backend, socket}, {raw, 1, 15, <<1:32/native>>}, {port, 8888}, {ip, any}]).
{error,eaddrinuse}

Erlang/OTP 23 [erts-11.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
Eshell V11.2 (abort with ^G)
1>
1> gen_tcp:listen(0, [{inet_backend, socket}, {raw, 1, 15, <<1:32/native>>}, {port, 8888}, {ip, any}]).
{ok,{'$inet',gen_tcp_socket,
{<0.83.0>,
{'$socket',#Ref<0.3300202661.3446013953.155967>}}}}
2>
2> gen_tcp:listen(0, [{inet_backend, socket}, {raw, 1, 15, <<1:32/native>>}, {port, 8888}, {ip, any}]).
{ok,{'$inet',gen_tcp_socket,
{<0.85.0>,
{'$socket',#Ref<0.3300202661.3446013953.155982>}}}}

I test in anther vps with otp 23.3 , this bug was fixed. "{inet_backend, socket}" option could listen mutiple sockets

@essen essen added this to the 2.1.0 milestone Sep 1, 2021
@essen
Copy link
Member

essen commented Sep 2, 2021

Should be fixed in the next OTP-24 release now that erlang/otp#5122 is merged. I will close the ticket. Thanks for the reports!

@essen essen closed this as completed Sep 2, 2021
@Maria-12648430
Copy link
Contributor

I read erlang/otp#5122, and Raimo tagged it for milestone 24.1. So I guess the fix won't be available before that, right?

@essen
Copy link
Member

essen commented Sep 2, 2021

Sounds like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants