Search code examples
iosswiftserverkillvapor

How to Kill Vapor Server


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.


Solution

  • 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.