Zombie phoenix server after quiting

Hi,

I quit phx.server using Ctrl+C and then a for Abort. This seems to leave the server process alive occupying port 4000. If I don’t kill the process, I can’t start the server again after that. I get the following error:

[error] Failed to start Ranch listener RumblWeb.Endpoint.HTTP in :ranch_tcp:listen([cacerts: :..., key: :..., cert: :..., port: 4000]) for reason :eaddrinuse (address already in use)

What am I doing wrong? Is there a better way to quit the server?

I am using macOS. Latest version of Erlang/Elixir/Phoenix.

Hello and welcome,

I usually use double ctrl-c.

1 Like

Thanks @kokolegorille. I just noticed this is probably not caused by Abort. Both Ctrl+c + a and double Ctrl+c seem to work fine now.

I think something else causes the server to become a zombie. Maybe it has to do with quiting the terminal without quiting the server? Although I tried that now and it quit properly.

I dunno. I am sorry for the noise. I will come back and post the cause if I discover it.

Just to make this a bit more useful in case anyone runs into the problem itself, here is how I check for what’s listening to 4000:

lsof -i -P -n | grep LISTEN | grep 4000

If there’s a process (Phoenix) and I know I had quit phx.server, I can kill it with kill -9 PID.

Could the sockets be temporarily stuck in a TIME_WAIT state? Not sure if phoenix sets SO_REUSEADDR. Some background info: https://www.thecodingforums.com/threads/how-to-reuse-tcp-listening-socket-immediately-after-it-was-connectedat-least-once.685380/

2 Likes