Can't start phx server: Could not start application - address already in use

when I try to start phoenix server, I got this error:

=INFO REPORT==== 12-Apr-2017::13:07:46 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application myapp: MyApp.start(:normal, ) returned an error: shutdown: failed to start child: MyApp.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, MyApp.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, MyApp.Endpoint.HTTP, :eaddrinuse}

I although I did not change anything before issue happened, any idea?

2 Likes

The error suggests that the port is in use. Maybe you have another app running on the same port

2 Likes

How to kill any process that uses 4000 port? I did not start any process on that port. Also, how did you know that this is the source of issue? could not notice this in the error log above.

1 Like

This line here is saying that the the http module failed to listen on the port (:listen_error) and the error was a :eaddrinuse, which just means the specified address is in use.

2 Likes

:eaddrinuse

finding the process depends on your OS - os x: lsof -i :4000

4 Likes

Thanks guys, I found the PID and killed it, it was phoenix server, but for some reason it wasn’t killed when I stopped the server.

2 Likes
** (EXIT) {:listen_error, MyApp.Endpoint.HTTP, :eaddrinuse}

should give you a hint. eaddrinuse is a posix error code that is returned when an address (combination of host and port) is in use.

To see what programs are listening at what addresses, you can use this oneliner on linux:

sudo lsof -i -P -n | grep LISTEN

Then kill -9 PID

8 Likes