Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 464
Dan Donaldson Avatar asked Feb 02 '21 04:02

Dan Donaldson


2 Answers

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.

like image 90
Caleb Kleveter Avatar answered Oct 25 '22 05:10

Caleb Kleveter


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 the port 8080) to the kill command as argument

like image 39
serg_zhd Avatar answered Oct 25 '22 06:10

serg_zhd