Shotgun Port is still in use?

Chris Houghton
2 min readApr 9, 2021

Error while working Sinatra, Shotgun Gem, and local server.

While working with Sinatra and Ruby ‘Shotgun’ gem, I tried to start a local server and received the error message:

/Users/ChrisHoughton/.rvm/gems/ruby-2.6.1/gems/eventmachine-1.2.7/lib/eventmachine.rb:531:in `start_tcp_server’: no acceptor (port is in use or requires root privileges) (RuntimeError)

The issue was I had no local server running, yet the server:9393 was in use.

So I checked the list of running processes in bash by typing:

$psPID TTY           TIME CMD
51846 ttys005 0:02.16 ruby /Users/ChrisHoughton/.rvm/gems/ruby-2.6.1/bin/shotgun

And there it was still running, although it had been terminated hours prior. After a little bit of research, I came across a simple fix to this dilemma.

First, find your ‘Process Identification Number/<PID>’ using bash command lsof (“list open files”) and -i (lists files that are opened by some network connections in the system.) and search for port 9393.

$ lsof -i :9393 #9393 is the Shotgun ServerCOMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby 51846 ChrisHoughton 15u IPv4 0x313a49cc861d7629 0t0 TCP localhost:9393 (LISTEN)

So now we have the <PID>, next we type

$ kill 51846 
# kill <pid>, kill -15 <pid>, kill -TERM <pid>, kill -SIGTERM <pid>

And the process has been gracefully terminated. The bash command $ kill will terminate the process with default kill signal SIGTERM which ends the process gracefully by allowing the application to determine when to stop, either immediately or after clearing up resources or not at all if not responsive where this command comes in handy

$ kill -KILL <pid> 
#kill -9 <pid>, -KILL <pid>, -SIGKILL <pid>

The process cannot ignore this command as it is handled outside of the process itself. The only exception to this command is the ‘Zombie Process’ states, they can only be cleared up using a reboot or finding and terminating the parent of the Zombie.

--

--