Search code examples
djangoheroku

Error: That Port is already in use (Heroku/Django)


When I run heroku local on my machine I get the following error:

07:44:21 web.1   |  Watching for file changes with StatReloader
07:44:22 web.1   |  Error: That port is already in use.
[DONE] Killing all processes with signal  SIGINT
07:44:22 web.1   Exited with exit code null

When I run sudo lsof -i tcp:5000 This is what I see:

COMMAND     PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 83303    x    19u  IPv4 0x874167a5a53a48c7      0t0  TCP *:commplex-main (LISTEN)
ControlCe 83303    x    20u  IPv6 0x874167a5922f00af      0t0  TCP *:commplex-main (LISTEN)

I've tried to kill the above processes using kill -9 but they don't seem to go away - I'm not sure if these are what are causing the issue either.

Any help appreciated.


Solution

  • It looks like port 5000 is used by "AirPlay Receiver" on macOS Monterey. The answer on that question shows how you can disable AirPlay Receiver in your System Preferences.

    But if you don't want to disable that feature you could also just use a different port. Django's default development port is 8000, so that might be a good choice.

    Assuming you have something like this in your .env file:

    PORT=5000
    

    simply change it to

    PORT=8000