Phoenix Framework - Ports Not Working As Expected

46 views Asked by At

After recently updating, I'm running into some strange behavior with my Phoenix project.

Basically, I have to keep changing the port number every time I relaunch the app. I have even tried terminating processes on said ports by PID, to no avail.

Trying to run mix phx.server on a "occupied" port yields the following error:

Could not start application project: Project.Application.start(:normal, []) returned an error: shutdown: failed to start child: ProjectWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, ProjectWeb.Endpoint.HTTP}
        ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
            ** (EXIT) {:listen_error, ProjectWeb.Endpoint.HTTP, :eaddrinuse}

This used to never be an issue on my machine (for ~4mo). Any ideas as to why this might be happening or how I could try and resolve this permanently without editing the port number every time?

(MacOS)

1

There are 1 answers

0
Danstan On

You are possibly exciting the terminal and leaving the old process still running. mix phx.server always creates a process called beam. Try doing pkill beam to terminate the old one before you restart/start.

Its recommended to start with iex -S mix phx.server in dev mode so that you type recompile in the app console to avoid restarts. Also check if your live reload is working so that you don't have to restart that.