14

I don't know what I did. I think I updated my Ruby on Rails. After updating it, I always get error when running $rails server.

output is

ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)

I would restart the console and run rails server and it would work fine for a couple of minutes but then it would stop responding and if I restart rails server it would give me that error again. I tried running on different port (rails s -p 9191) and it gives me the same problem.

Any Ideas what I did wrong? Thnx guys

fl00r
  • 82,987
  • 33
  • 217
  • 237
hlim
  • 945
  • 1
  • 9
  • 16

3 Answers3

34

run it on other port:

rails s -p 3001

so it'll load on localhost:3001

or kill all ruby processes:

killall ruby

and then run rails s

fl00r
  • 82,987
  • 33
  • 217
  • 237
  • when I tried rails s -p 3001, it work but then if i restarted it and run it again I would get the error "Already in use - bind(2) Errno::EADDRINUSE)...." I also tried killall ruby but didn't work. It's weird cause I also tried it on my other laptop and it's giving me the same error. Does it have to do with my router or something? – hlim Aug 11 '11 at 20:15
  • and yes - it looks like something wrog with your `localhost` environment – fl00r Aug 11 '11 at 20:17
  • mac OS X (10.6.8). I would start rails server on different port and wouldn't give me errors and restart it right after and it would give me the error. – hlim Aug 11 '11 at 20:17
  • so I believe it is network problem. Try to disconnect from your network and run rails in offline – fl00r Aug 11 '11 at 20:18
  • yea tried doing it offline. still the same error. This is version im running Rails 3.0.9 and ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] – hlim Aug 11 '11 at 20:22
  • what does this return: `ps aux | grep ruby` and `ps aux | grep rail` – fl00r Aug 11 '11 at 20:24
  • ruby-1.9.2-p290/bin/ruby script/rails s AND ruby script/rails s -p 3002 AND ruby script/rails s -p 8080 AND ruby script/rails s -p 3001 – hlim Aug 11 '11 at 20:29
  • and `sudo killall -9 ruby` do nothing? – fl00r Aug 11 '11 at 20:31
  • yea it doesn't seems to kill the process after doing sudo killall ruby then I did ps aux | grep ruby, it still show scripts/rails -p 3001, script/rails -p 9090 ..... wait sorry forgot to put -9 option yea it killed everything. Tried rails server but still same problem – hlim Aug 11 '11 at 20:35
  • `ps aux | grap webrick` or you use mongrel? – fl00r Aug 11 '11 at 20:38
  • this is what I get from ps aux | webrick "56265 0.0 0.0 2435116 412 s000 R+ 1:42PM 0:00.00 grep webrick" no i don't think I use mongrel – hlim Aug 11 '11 at 20:43
  • these are some errors I get from running rails s "/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/utils.rb:73:in `new'" and ".rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/utils.rb:73:in `block in create_listeners'" – hlim Aug 11 '11 at 20:48
  • I don't know. Try to update all your gems. Very strange. Looks like `ctrl+c` didn't stop webrick at all, so port is binded by it – fl00r Aug 11 '11 at 20:55
  • reboot your machine - I get this problem from time to time on ubuntu – stephenmurdoch Aug 11 '11 at 21:03
  • I think my ctrl+c is not stoping rails server properly. Everytime I restart my server I need to manually "killall ruby" to start rails server again. – hlim Aug 11 '11 at 21:17
  • oh man this is so stupid of me. I was using ctrl+z all this time to kill my server. I don't know why suddenly I was using ctrl+z instead of ctrl+x . Stupid of me. Thnx fl00r for your help. I feel so stupid now.... – hlim Aug 11 '11 at 21:35
  • So that's something, all the other answers I've seen just tell you how to kill the pid and add a new one. – JackHasaKeyboard Dec 29 '15 at 03:49
  • `killall ruby` was not able to kill the process started in chrome by the Jetbrains IDE support - https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji – Vipin Verma Feb 12 '16 at 19:11
22

I think somehow your rails server is keep running after you close it. You can try as

ps aux | grep ruby

see pid and then kill that pid

kill -9 <pid>

Now you can restart your server using

rails s

Note: From next time onwards try using Ctrl D for terminating rails server. That might help

ducktyped
  • 4,354
  • 4
  • 26
  • 38
1

I too faced the issue it all because of ruby instances are not properly terminated.We can terminate processes running in the background by pids.

lsof -wni tcp:3000

It displays all running pids of ruby.and terminate that pids.

kill -9 PID

Or use

killall ruby
Dinesh Pallapa
  • 1,172
  • 18
  • 20