5
votes

I'm trying to build a very simple service using Vapor. It depends on websockets, and I establish a connection between an iOS device in simulator and vapor running on localhost.

When I want to make changes to the server, I restart and sometimes get [ ERROR ] bind(descriptor:ptr:bytes:): Address already in use (errno: 48)

I don't know how to find and kill this process, which is a socket running on 8080. I have to restart to get out of it, and I feel like throwing the computer out the window after a few repetitions (question about that already asked in mentalHealthOverflow.com).

How can I find and kill this process? Stopping the simulator device doesn't do it.

2
Does this answer your question? How do I Kill a Vapor Server?imike
Clearly not, Mike. We had a power outage here in dear old Phnom Penh, and I wasn't aware my original posting had not been lost.Dan Donaldson
This question discussed a lot of times in Discord chat. Simplest way to kill the process is to open Activity Monitor, search for process with name Run (or how your app called) and just force kill it. It is the problem in the latest Xcode that it wont kill the process properly with kill 9 command.imike
thanks! I found the discord #vapor stream, much better than most documentation....Dan Donaldson

2 Answers

7
votes

The fix is actually pretty easy. Go to your terminal and run lsof -i :<port>, so in your case, lsof -i :8080. You will get an output of all the processes that are running on that port.

COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Run     48904 calebkleveter   31u  IPv4 0x97c38af35a1b4785      0t0  TCP localhost:Run (LISTEN)

You can then run the kill command, passing in the PID from the output you got:

kill 48904

You can now run your Vapor service.

0
votes

Oneliner that I use:

lsof -i :8080 -sTCP:LISTEN | awk 'NR > 1 {print $2}' | xargs kill -15

Which basically just sends PID of the Vapor process (running on port 8080) to the kill command as argument