Thin web server: `start_tcp_server': no acceptor (RuntimeError) after git branch checkout
Asked Answered
B

9

110

A Rails 3.2.0 app, working fine with Thin web server, both locally and on Heroku cedar stack.

After:

$ git branch work
$ git checkout work
$ rails server

I get:

=> Booting Thin
=> Rails 3.2.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
/Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_tcp_server': no acceptor (RuntimeError)
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_server'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/tcp_server.rb:16:in `connect'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:53:in `block in start'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.0/lib/rails/commands/server.rb:70:in `start'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.0/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.0/lib/rails/commands.rb:50:in `tap'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.0/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Also, when I do:

sudo bundle exec rails server thin -p 3000

I get:

/Users/peter/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /Users/peter/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/peter/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /Users/peter/.rvm/gems/ruby-1.9.3-p125/bin/bundle:18:in `<main>'

I have bundler 1.0.22 installed. Updated and installed it. Nothing seems to work. Any ideas?

Banebrudge answered 7/3, 2012 at 16:31 Comment(4)
Do you already have a server running elsewhere on the machine? Perhaps in Cucumber or something?Zeuxis
No, I haven't. Actually, restarting my computer had solved my problem. Today it happened again. Seems to happen when I switch over from one git branch to another.Banebrudge
Thanks! My error message on MacOSX was ... eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError).Prophylaxis
Same for me when I tried to use the same port to run two different application. This topic just made me think about the other running application.Tbar
M
226

This works for me. Find (zombie?) server (can happen when quitting terminal with server running):

$ ps ax | grep rails

If it returns something like:

33467 s002 S+ 0:00.00 grep rails
33240 s003 S+ 0:15.05 /Users/Arta/.rbenv/versions/1.9.2-p290/bin/ruby script/rails s -p 3000

kill it, and run anew:

$ kill -9 33240
$ rails s
Mesomorphic answered 15/8, 2012 at 17:9 Comment(2)
If ps ax | grep rails doesn't turn up anything, try ps ax | grep ruby.Biped
Definitely happens on OSX if you straight quit the terminal window while the rails server is running. +1Interpose
E
63

The port 3000 may already be in use. Look at http://mrjaba.posterous.com/starttcpserver-no-acceptor-runtimeerror

Earphone answered 23/3, 2012 at 14:41 Comment(1)
From the above-linked article, a command to locate rails servers already running (works on mac): ps aux | grep railsRataplan
B
48

If there's any other process locking the port, you can find out which PID it has like this:

$ lsof -i :3000
COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Passenger 40466 josh    5u  IPv4 0x7cae9332073ed4df      0t0  TCP *:hbci (LISTEN)
Passenger 40467 josh    5u  IPv4 0x7cae9332073ed4df      0t0  TCP *:hbci (LISTEN)

Then simply kill it/them:

$ kill -9 40466
$ kill -9 40467
Boynton answered 10/2, 2014 at 10:5 Comment(1)
ntop was using port 3000 on my machine. Answer is spot on.Graycegrayheaded
P
47

pgrep ruby to see what servers are running and then

kill -9 serverNumber

;)

Playboy answered 2/8, 2012 at 13:14 Comment(0)
S
8

rvmsudo rails server thin -p 3000

Does it for me

Sedge answered 13/6, 2012 at 15:58 Comment(0)
K
6

I has this error because i was running rails-dev-box with Rails inside of it.

Port 3000 in the host computer is forwarded to port 3000 in the virtual machine. 
Thus, applications running in the virtual machine can be accessed via 
localhost:3000 in the host computer.

So is logged out from Vagrant and shutted down it:

vagrant@rails-dev-box:/vagrant/rails$ exit
$ vagrant halt

That helped me.

Klaxon answered 10/2, 2014 at 8:13 Comment(1)
I had the same problem. I had vagrant running from a separate project. Probably not common, but it helped me. Thanks! +1Chemotherapy
D
5

I had this error because I was already running rails in another terminal. Closing my other project fixed this.

Discomfiture answered 16/5, 2014 at 22:3 Comment(3)
If you want to run both programs at once, you can start your second server on a different port.Biped
@Biped great point. That wasn't was I trying to do, has just forgot that the other project was running.Discomfiture
@DJ That makes sense. I was posting my comment for future readers :)Biped
C
2

I ran into a similar issue after getting back to the office from vacation. I run my server on the local IP as:

rails s thin -b <my_ip>

The problem was that my IP had changed, I just needed to use the new one.

Chelseachelsey answered 2/12, 2013 at 14:9 Comment(0)
P
2

Execute this in the terminal

sudo netstat -lpn |grep rails

And then

sudo kill <job id>
Pettifer answered 30/9, 2014 at 10:31 Comment(3)
This was the only way I was able to find my processes, though I had to grep for thin instead of rails.Teresita
Yes it works most of the cases. If you liked vote up please.Pettifer
Finding and killing the process id did the trick. Though the first command didn't worked for me but ps aux | grep rails.Bosley

© 2022 - 2024 — McMap. All rights reserved.