TCPServer Error: Address already in use - bind(2)
Asked Answered
L

9

93

Jekyll was working fine for me few weeks back but now all of a sudden it gives me the following error:

TCPServer Error: Address already in use - bind(2)
INFO  WEBrick::HTTPServer#start: pid=7300 port=4000

 % lsof -i :4000
 <fetches nothing>

Even though nothing is running on the port. Below are the details:

 % jekyll --version
Jekyll 0.11.2
 % where jekyll
/home/bhaarat/.rvm/gems/ruby-1.9.2-p290/bin/jekyll
/usr/bin/jekyll
 % ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
 % rvm --version
rvm 1.10.0 

Here is the output

 % jekyll --server
Configuration from /home/bhaarat/blog/omnipresent.github.com/_config.yml
Auto-regenerating enabled: /home/bhaarat/blog/omnipresent.github.com -> /home/bhaarat/blog/omnipresent.github.com/_site
[2012-04-21 13:46:40] regeneration: 38 files changed
[2012-04-21 13:46:40] INFO  WEBrick 1.3.1
[2012-04-21 13:46:40] INFO  ruby 1.9.2 (2011-07-09) [i686-linux]
[2012-04-21 13:46:40] WARN  TCPServer Error: Address already in use - bind(2)
[2012-04-21 13:46:40] INFO  WEBrick::HTTPServer#start: pid=7382 port=4000

I know the address isn't in use and jekyll is probably breaking for some other reason but throwing that error. What are my options? I've tried re-installing as well.

Leitao answered 21/4, 2012 at 17:48 Comment(11)
How exactly do you know the address isn't in use?Gable
i'm trying lsof -i :<port number> plus same thing is happening on a different boxLeitao
What happens if you specify an alternate port?Entablature
unfortunately, the same thing. Whats the best way to completely remove jekyll and reinstall it.Leitao
If you used Ruby gem to install, you should be able to uninstall with gem uninstall jekyll. If you didn't maybe install with gem to overwrite the existing version. Did you try hitting the port with your browser or telnet to see if that provides any help?Poriferous
Have you tried going to localhost:4000 while Jekyll is running? I get the same warning but the server still works.Hudibrastic
Have you tried with sudo to see what is running on the port? I mean sudo fuser -n tcp 8080Simson
The thing is, nothing listens on :4000. Something is broken in Jekyll.Altissimo
Did you try jekyll --no-server --no-auto? I get found character that cannot start any token while scanning for the next token at line 2 column 1 (Psych::SyntaxError). jekyll --server is similar to yours.Altissimo
Friggin Ruby based BS always has the dumbest bugs. How on earth can someone get wrong whether a port is in use? Why the hell does Bootstrap 3 use this buggy crap.Popp
I had to sudo the lsof command. Without sudo, lsof returned nothing.Betteanne
B
235

Type this in your terminal to find out the PID of the process that's using the 3000 port:

$ lsof -wni tcp:3000

Then, use the number in the PID column to kill the process:

$ kill -9 PID
Buhl answered 21/10, 2012 at 19:29 Comment(3)
To anyone reading this, make sure that in the last command, you substitute PID with the actual number that you see under the PID. for example, I ran kill -9 11734Precedent
Note that the problem can also be a harmless warning coming from an IPv6 configuration issue: the server first binds to a dual-stack IPv4+IPv6 address, then it also tries to bind to a IPv6-only address; and the latter doesn't work because the IPv6 address is already taken by the previous dual-stack socket.Misnomer
try this instead lsof -wni tcp:3000 | xargs -I{} kill -9 {} of running both commandEllipsoid
S
18

I was not qualified to post comment. So I added a new answer.

I encountered this problem on Mac OS X 10.10.3. And I had never installed/used Jekyll before. I was not able to start jekyll server with its default port number 4000. The reason was that the port was the same as what NoMachine used. With

$ sudo lsof -wni tcp:4000

Note: Running this command without sudo will have no output.

I saw this output:

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nxd     449   nx    3u  IPv4 0x8d22************      0t0  TCP *:terabase (LISTEN)
nxd     449   nx    4u  IPv6 0x8d22************      0t0  TCP *:terabase (LISTEN)

The port 4000 was occupied by nxd, which was the process started by NoMachine. And

$ sudo kill -9 449

would not work, because NoMachine's nxd process would keep restarting, with a new PID.

Therefore, I had to either:

  • Changed my jekyll server port in the site _config.yml to another spared one. I appended the line below to _config.yml and it worked.

    port: 3000 # change server port to 3000

or

  • Changed NoMachine's default nxd port, or Uninstall NoMachine
Slav answered 16/6, 2015 at 14:53 Comment(1)
Thanks, I couldn't figure out what terabase was until I stumbled upon this answer.Commentary
S
11

Ctrl-Z doesn't terminate a program, but rather suspends it and sends it to the background. You can resume the program with the "fg" command. To actually terminate it, use Ctrl-C.

The actual error message seems to be bogus and can be ignored. I am getting the same error message "address in use" but jekyll works fine anyway at the expected port.

Schilt answered 14/11, 2012 at 9:23 Comment(1)
I am also getting the error message but I can run my site off :4000Imperceptible
A
3

I have met this problem recently.

I tried out all the method mentioned above, and even restarted my computer, but still couldn't solve it!!! Then I removed the jekyll and installed a new version, it just worked.

gem uninstall jekyll & gem install jekyll (maybe you need super user priviledge).

If you really get annoyed with similar bugs, this sb method is worth a try...

Academicism answered 19/9, 2013 at 7:15 Comment(0)
E
1

Based on the top answer, I came up with a simple way

lsof -wni tcp:3000 | xargs -I{} kill -9 {}

It takes the output of finding PID in which port the tcp server is running at. In this case it is 3000.

It then kills the processes running that PID

Ellipsoid answered 27/8, 2022 at 3:27 Comment(0)
C
0

Check that you don't have another terminal open where you are already running a server. If that is the case, do a CTRL-C to shutdown the server, and that will free the port/address.

Crenulation answered 27/1, 2015 at 4:22 Comment(0)
C
0

First you need to find PID of the process that's using the 3000 port:

 $ps -ef

Output Like this:

1003      4953  2614  0 08:51 pts/0    00:00:00 -bash
1003      5634     1  0 08:56 pts/0    00:00:00 spring server | moviestore | started 2 hours ago                                           
1003      5637  5634  0 08:56 ?        00:00:01 spring app    | moviestore | started 2 hours ago | development mode                                                              
1003      6078  4953  0 09:03 pts/0    00:00:03 puma 3.6.0 (tcp://localhost:3000) [moviestore]              
1003      6117  2614  0 09:03 pts/1    00:00:00 -bash
root      6520     2  0 09:57 ?        00:00:00 [kworker/u8:2]
root      6936  1225  0 11:09 ?        00:00:00 [lightdm] <defunct>
1003      7084     1  0 11:09 ?        00:00:00 /usr/bin/python /usr/share/apport/apport-gtk
1003      7475     1  0 11:10 ?        00:00:00 /usr/bin/python /usr/share/apport/apport-gtk
root      8739  1225  1 11:29 tty8     00:00:11 /usr/bin/X :1 -auth /var/run/lightdm/root/:1 -nolisten tcp vt8 -novtswitch
root      8853  1225  0 11:29 ?        00:00:00 lightdm --session-child 13 22
1002      8943     1  0 11:30 ?        00:00:00 /usr/bin/gnome-keyring-daemon --daemonize --login
1002      8954  8853  0 11:30 ?        00:00:00 gnome-session --session=ubuntu
1002      8992  8954  0 11:30 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1002      8995     1  0 11:30 ?        00:00:00 /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1002      8996     1  0 11:30 ?        00:00:00 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
1002      9007  8954  0 11:30 ?        00:00:00 /usr/lib/gnome-settings-daemon/gnome-settings-daemon
1002      9015     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfsd
1002      9018  8954  1 11:30 ?        00:00:07 compiz
1002      9021     1  0 11:30 ?        00:00:00 /usr/lib/x86_64-linux-gnu/gconf/gconfd-2
1002      9028  8954  0 11:30 ?        00:00:00 /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1
1002      9029  8954  0 11:30 ?        00:00:01 nautilus -n
1002      9030  8954  0 11:30 ?        00:00:00 /usr/lib/gnome-settings-daemon/gnome-fallback-mount-helper
1002      9031  8954  0 11:30 ?        00:00:00 nm-applet
1002      9032  8954  0 11:30 ?        00:00:02 /opt/mTrac/mTrac
1002      9033  8954  0 11:30 ?        00:00:00 bluetooth-applet
1002      9045  9032  0 11:30 ?        00:00:00 /opt/mTrac/mTrac --type=zygote --no-sandbox
1002      9050     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-gdu-volume-monitor
1002      9054     1  0 11:30 ?        00:00:00 /usr/bin/pulseaudio --start --log-target=syslog
1002      9057     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
1002      9062     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-afc-volume-monitor

here you can see :

1003      6078  4953  0 09:03 pts/0    00:00:03 puma 3.6.0 (tcp://localhost:3000) [moviestore]   

localhost:3000 have pid: 6078

kill that process by

$sudo kill 6078  

then run

$rails s
Concertmaster answered 29/8, 2016 at 6:23 Comment(0)
O
0

we can user fuser command

fuser -k 3000/tcp

Oppugnant answered 1/5, 2020 at 10:17 Comment(0)
R
-1

work around

in /_site run: python -m SimpleHTTPServer 8080

Rife answered 24/3, 2014 at 4:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.