process won't die after being killed with `kill` command - ruby-on-rails

I'm trying to run rails server to start a local server but got this error
...
WARN TCPServer Error: Address already in use - bind(2)
Exiting
...
So I went and looked for the process that was occupying the port and killed it.
The server still wouldn't start.
And as it turned out, lsof still showed the process (even after it had been killed):
$ lsof -P | grep ':3000'
ruby 52944 user 7u IPv4 0xffffff800bdafbd8 0t0 TCP *:3000 (LISTEN)
$ kill 52944 <<<<<<< pid 52944 should have died here!
$ lsof -P | grep ':3000'
ruby 52944 user 7u IPv4 0xffffff800bdafbd8 0t0 TCP *:3000 (LISTEN)
Any idea how to really kill the process?
(This is on OSX)

Use
kill -9 <id>
to kill stubborn processes :-)

Related

How to kill running "invisible" containers?

I installed docker using snap (during the install process of 22.04) and it was working fine, and all my containers were spun up using docker run ...
This was until I installed docker-compose using apt later on. When I attempted to bring up containers with docker-compose I would get errors stating that the port was already in use.
So I then checked what program/command was using these ports:
sudo lsof -i :9091:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 1883 root 4u IPv4 28696 0t0 TCP *:9091 (LISTEN)
docker-pr 1890 root 4u IPv6 27395 0t0 TCP *:9091 (LISTEN)
sudo netstat -pna | grep 9091
tcp 0 0 0.0.0.0:9091 0.0.0.0:* LISTEN 1883/docker-proxy
tcp6 0 0 :::9091 :::* LISTEN 1890/docker-proxy
This showed that my container was still somehow running, as the port was in use. However, when running docker ps -a no containers were running...
The commands above all pointed towards docker-proxy, what is this service? Also, why is it so under the radar that docker itself can't even stop the container with commands like: docker rm $(docker ps -aq)? Also, not sure why my container became invisible and was unable to stop it without stopping the docker service entirely.

Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use

I am trying to follow a tutorial for Docker beginners (https://docs.docker.com/get-started/)
When I try to run this command:
$ docker run -d -p 80:80 docker/getting-started
I get this Error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint suspicious_murdock (863f389a032ea76d187c4387701b9eb0b6d4de4d0a9ed414616fa6b4715346ab): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
I tried removing all the dockers docker rm -fv $(docker ps -aq) but it did nothing.
What can I do?
I had to stop apache2 from running on port :80 - sudo service apache2 stop
Or you can use a different port like docker run -d -p 8080:80 docker/getting-started. This way you do not need to stop the apache2 running on the host.
In case you change ports and still encounter the same problem especially on Ubuntu 18 try stopping your apache serve and mysql/mariadb port if you further encounter mysql/mariadb port already been used.
Try these two commands.
sudo service apache2 stop
sudo service mysql stop
sudo service mariadb stop
why is this error showing?
This error means that you have a process listening to port 80 (the default HTTP port). This is probably a server of some sorts like apache/nginx/lighttpd.
Other answers suggest closing a database (mysql/mariadb), but - if configured correctly - they will be using a different port (most often 3306). This means that stopping your database will probably not solve the issue, since they are not using port 80.
how to find out what is causing this?
from here:
In a terminal type (with sudo, so it also shows root processes):
sudo lsof -i :80
you should get something like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
lighttpd 1713 www-data 4u IPv6 36989 0t0 TCP *:http (LISTEN)
lighttpd 1713 www-data 5u IPv4 36990 0t0 TCP *:http (LISTEN)
firefox-b 23384 your-user 150u IPv4 122957 0t0 TCP pop-os:37322->ef-in-f94.1e100.net:http (ESTABLISHED)
firefox-b 23384 your-user 174u IPv4 122155 0t0 TCP pop-os:37314->ef-in-f94.1e100.net:http (ESTABLISHED)
Note the (LISTEN) vs (ESTABLISHED) at the end. (LISTEN) is the culprit here, caused by the command lighttpd, which is a server. Also, the USER of lighttpd is www-data, which is not you, so it would not show without sudo.
Now, to stop it, use:
sudo service stop lighttpd
where you replace lighttpd with whatever the command is (of course you kind of want to know what you're doing here, since you don't accidentally want to pull your website offline).

rails: port is in use or requires root privileges

I am getting this error when attempting to start up a rails 4.1.1 server:
Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.1.2#myflix/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
I have tried the following commands to find and kill the process, however none of them reveal any servers running on 3000
ps ax | grep rails
ps ax | grep ruby
lsof -i TCP | grep LISTEN
lsof -i :3000
These, from my research on stack overflow, seem to be all of the available methods for discovering running ports.
In a rails 5 application I am getting the following similar error:
Listening on tcp://0.0.0.0:3000
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.3.1/gems/puma-3.7.0/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
Note that I can start rails servers on other ports.
This error persists even after machine reboot. Seems I have exhausted all avenues for finding and killing ports in use. What other things can I try?
UPDATE:
#hjpotter92 suggests running:
netstat -lntp | grep 3000
This however does not work as an option is required for the p argument. According to man netstat the list of protocols is found in etc/protocols.
I looked in that file and found that tcp is a listed protocol. However, this command does not return any output:
netstat -lntp tcp | grep 3000
Nor does this command return anything either:
netstat -lnt | grep 3000
You can try scanning the port like this lsof -i :3000 and then kill the process using sudo kill -9 <PID>.
Well, it turns out the answer to this is fairly obscure. The Node instance of FileMaker server 16 is running on port 3000. I was running a FileMaker server on the my Rails development machine.
This command helped to discover that:
sudo lsof -P -i :3000
Result
node 562 fmserver 20u IPv6 0x3ef1908b38776fe5 0t0 TCP *:3000 (LISTEN)
I could kill that process, however elected instead to disable the Node instance (The FileMaker REST/Data API).
Documentation here shows that FileMaker 16 is using that port.
http://help.filemaker.com/app/answers/detail/a_id/16319

Address already in use - bind(2) when starting server in Cloud9 IDE

When starting the server in Cloud9, rails s -p $PORT -b $IP, I get an error and the server fails to start.
Address already in use - bind(2)
Following this post, Rails server says port already used, how to kill that process?,
I ran lsof -wni tcp:8080 (8080 because of cloud9)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 18415 ubuntu 9u IPv4 698526934 0t0 TCP *:http-alt (LISTEN)
Then,
kill -18415 PID
But this results in an error,
bash: kill: 18415: invalid signal specification
Can anyone advise how to fix this error on Cloud9?
You're killing it with the wrong way.
You need to use:
kill -9 18415
9 - signal 'kill'
18415 - process id
Also you can kill all ruby processes like this:
killall -9 ruby
But use it only when you know what you're doing.

MQTT-over-Websockets Error: listen EADDRINUSE

Following this doc
https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets
I set up the broker in my localhost like
var settings = {
http: {
port: 1884,
bundle: true,
static: './'
}
};
//here we start mosca
var server = new mosca.Server(settings);
but when I run
node broker
I've got this ugly error
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1146:14)
at listen (net.js:1172:10)
at net.js:1270:9
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
to check if I've got other process
ps -ax | grep node
5266 pts/2 R+ 0:00 grep --colour=auto node
kill -9 5266
bash: kill: (5266) - No such process
Do you what's the problem ?
UPDATE
Thanks to #hardillb and #ralight
I worked it out with
sudo lsof -i TCP:1883
if there is mosquitto simple
run
sudo service mosquitto stop
This shows the current sockets that are listening on your machine:
sudo netstat -ltn
You would expect to see something like the below if something is listening.
tcp 0 0 0.0.0.0:1884 0.0.0.0:* LISTEN
If LISTEN is replaced with TIME_WAIT, then it is possible there is a bug in mosca which doesn't allow it to reuse a listening socket that hasn't timed out. I think that is unlikely though.
To find the process using the port, you can use lsof:
sudo lsof -i TCP:1884
This will give an output something like the example below that I got by running sudo lsof -i TCP:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 3878 root 3u IPv4 4505 0t0 TCP *:ssh (LISTEN)
It might not be a node process that is holding the socket
Try running sudo lsof -i :1884 to see what process it might me.
Also have you tried changing the port number to something other than 1884 to see if it works.

Resources