TCPServer Error: Address already in use error
This little error has been popping up occasionally in my local rails development environment using the WEBrick server.
I generally just use the default 0.0.0.0 ip address with a different port assigned to it depending on the app I am running. There may be a better way of running local development servers that I don’t know about but this has always been quick and flexible enough for my uses.
As default, when starting WEBrick, the server attempts to bind to port 3000. If you have already got another app running on 0.0.0.0:3000 the following error will rear it’s head.
=> Booting WEBrick=> Rails 3.0.0 application starting in development onhttp://0.0.0.0:3000=> Call with -d to detach=> Ctrl-C to shutdown server[2010-09-12 15:34:34] INFO WEBrick 1.3.107[2010-09-12 15:34:34] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0]08[2010-09-12 15:34:34] WARN TCPServer Error: Address alreadyin use - bind(2)Exiting10/Users/eford/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
Two options are available that will either fix the issue or just get around it.
WEBrick allows the port bind to be defined when start by passing the port number through the start command:
rails s -p=3001
To reuse the default server setting, you wil first need to need to free the address by killing the process.
On a Mac, use the terminal window to view the processes
ps aux | grep rails
You should see something like
eford 14290 …. /Users/eford/.rvm/rubies/ruby-1.9.2-p0/bin/ruby script/rails s
Depending on your setup, the path will be different but it is the .ruby script/rails s to look for. Kill the process using kill -9 <pid>. The -9 will stop the process without question
Once stopped, try starting the server again with rails s
rails s=> Booting WEBrick=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000=> Call with -d to detach=> Ctrl-C to shutdown server[2010-09-12 15:42:11] INFO WEBrick 1.3.17[2010-09-12 15:42:11] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0][2010-09-12 15:42:11] INFO WEBrick::HTTPServer#start: pid=14290 port=30009=> Booting WEBrick=> Rails 3.0.0 application starting indevelopment on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server[2010-09-12 15:42:11] INFO WEBrick 1.3.1[2010-09-12 15:42:11] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0][2010-09-12 15:42:11] INFO WEBrick::HTTPServer#start: pid=14290 port=3000
Try 0.0.0.0:3000 in your browser now and you should have your app
1 Notes/ Hide
-
miurafkin liked this
-
edwardford posted this

