Alexander Doloz Alexander Doloz - 3 months ago 113
Swift Question

Could not bind to, it may be in use or require sudo

Sometimes I get this error when trying to run a Vapor application from Xcode. Reopening Xcode doesn't help, only restarting of system do. Is it a bug of the framework? What should I do to prevent this?


If using sudo does not fix this message, it means something is already bound to this port. It could be an instance of Vapor that didn't close correctly.

To fix this, you need to kill the previous instance. The easiest way to do this is:

lsof -i tcp:8080

Where 8080 is the port you are trying to use. This outputs something like:

COMMAND    PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME 4679 tanner    8u  IPv4 0x890f6b0b31966939      0t0  TCP 

Then kill the process bound to that port using its PID.

kill 4679