Ranch_listener_sup problem when phoenix server is started in Manjaro

Hello there,
With asdf assistance, I set up Erlang version 25.0.3 and Elixir version 1.13.4 on my system.

Erlang/OTP 25 [erts-13.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Elixir 1.13.4 (compiled with Erlang/OTP 25)

After that, I used the document to install Phoenix on my system.
I tried to start the Phoenix server by typing iex -S mix phx.server on my Linux Manjaro operating system after building a Phoenix project, but I regrettably received the following error,
Though it wasn’t my issue, I had seen this topic.
Please advise me.

❯ iex -S mix phx.server
Erlang/OTP 25 [erts-13.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

[error] Failed to start Ranch listener YekEsmiWeb.Endpoint.HTTP in :ranch_tcp:listen([cacerts: :..., key: :..., cert: :..., ip: {127, 0, 0, 1}, port: 4001]) for reason :eaddrinuse (address already in use)

[notice] Application yek_esmi exited: YekEsmi.Application.start(:normal, []) returned an error: shutdown: failed to start child: YekEsmiWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, YekEsmiWeb.Endpoint.HTTP}
        ** (EXIT) an exception was raised:
            ** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: not a key that exists in the table

                (stdlib 4.0.1) :ets.lookup_element(:ranch_server, {:addr, YekEsmiWeb.Endpoint.HTTP}, 2)
                (ranch 1.8.0) /home/husen/Documents/elixir/yek_esmi/deps/ranch/src/ranch_server.erl:113: :ranch_server.get_addr/1
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:119: Phoenix.Endpoint.Cowboy2Adapter.bound_address/2
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:115: Phoenix.Endpoint.Cowboy2Adapter.info/3
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:101: Phoenix.Endpoint.Cowboy2Adapter.start_link/3
                (stdlib 4.0.1) supervisor.erl:414: :supervisor.do_start_child_i/3
                (stdlib 4.0.1) supervisor.erl:400: :supervisor.do_start_child/2
                (stdlib 4.0.1) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
                (stdlib 4.0.1) supervisor.erl:1250: :supervisor.children_map/4
                (stdlib 4.0.1) supervisor.erl:350: :supervisor.init_children/2
                (stdlib 4.0.1) gen_server.erl:848: :gen_server.init_it/2
                (stdlib 4.0.1) gen_server.erl:811: :gen_server.init_it/6
                (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
[notice] Application plug_cowboy exited: :stopped
[notice] Application cowboy_telemetry exited: :stopped
[notice] Application cowboy exited: :stopped
[notice] Application ranch exited: :stopped
[notice] Application cowlib exited: :stopped
[notice] Application gettext exited: :stopped
[notice] Application telemetry_poller exited: :stopped
[notice] Application swoosh exited: :stopped
[notice] Application jason exited: :stopped
[notice] Application xmerl exited: :stopped
[notice] Application esbuild exited: :stopped
[notice] Application castore exited: :stopped
[notice] Application phoenix_live_dashboard exited: :stopped
[notice] Application telemetry_metrics exited: :stopped
[notice] Application phoenix_live_view exited: :stopped
[notice] Application phoenix_live_reload exited: :stopped
[notice] Application file_system exited: :stopped
[notice] Application phoenix_html exited: :stopped
[notice] Application postgrex exited: :stopped
[notice] Application ecto_sql exited: :stopped
[notice] Application db_connection exited: :stopped
[notice] Application connection exited: :stopped
[notice] Application phoenix_ecto exited: :stopped
[notice] Application ecto exited: :stopped
[notice] Application decimal exited: :stopped
[notice] Application phoenix exited: :stopped
[notice] Application phoenix_view exited: :stopped
[notice] Application phoenix_pubsub exited: :stopped
[notice] Application plug exited: :stopped
[notice] Application telemetry exited: :stopped
[notice] Application plug_crypto exited: :stopped
[notice] Application mime exited: :stopped
[notice] Application eex exited: :stopped
[notice] Application runtime_tools exited: :stopped
** (Mix) Could not start application yek_esmi: YekEsmi.Application.start(:normal, []) returned an error: shutdown: failed to start child: YekEsmiWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, YekEsmiWeb.Endpoint.HTTP}
        ** (EXIT) an exception was raised:
            ** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: not a key that exists in the table

                (stdlib 4.0.1) :ets.lookup_element(:ranch_server, {:addr, YekEsmiWeb.Endpoint.HTTP}, 2)
                (ranch 1.8.0) /home/husen/Documents/elixir/yek_esmi/deps/ranch/src/ranch_server.erl:113: :ranch_server.get_addr/1
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:119: Phoenix.Endpoint.Cowboy2Adapter.bound_address/2
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:115: Phoenix.Endpoint.Cowboy2Adapter.info/3
                (phoenix 1.6.11) lib/phoenix/endpoint/cowboy2_adapter.ex:101: Phoenix.Endpoint.Cowboy2Adapter.start_link/3
                (stdlib 4.0.1) supervisor.erl:414: :supervisor.do_start_child_i/3
                (stdlib 4.0.1) supervisor.erl:400: :supervisor.do_start_child/2
                (stdlib 4.0.1) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
                (stdlib 4.0.1) supervisor.erl:1250: :supervisor.children_map/4
                (stdlib 4.0.1) supervisor.erl:350: :supervisor.init_children/2
                (stdlib 4.0.1) gen_server.erl:848: :gen_server.init_it/2
                (stdlib 4.0.1) gen_server.erl:811: :gen_server.init_it/6
                (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

The important part of the error message is:

It seems that port 4001 is already in use on your machine.

for this reason, I changed from 4000 to 4001, but I still have the same problem
port 4001 is also empty

❯ fuser 4001/tcp
#empty

Not sure how fuser works, but can you run:

ss -tulpn | grep "LISTEN"

and check if 4001 is used?

I think so

tcp   LISTEN 0      4096                [::]:4000          [::]:*    
                                    
tcp   LISTEN 0      4096                [::]:4001          [::]:*

Try running it with sudo. That should show the process, which is using the port in the last column.

2 Likes
tcp   LISTEN 0      4096                [::]:4000          [::]:*    users:(("docker-proxy",pid=1950,fd=4))

tcp   LISTEN 0      4096                [::]:4001          [::]:*    users:(("docker-proxy",pid=1928,fd=4))

I shut down Docker and the problem was solved.
thank u :green_heart:

1 Like