Sunday, 27 August 2006

Errno::EBADF

Note: The RichText blog has moved to www.ricroberts.com

Sometimes, when trying to start my rails server with the usual command:

ruby script/server
I get the following error:

=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-08-27 15:10:09] INFO WEBrick 1.3.1
[2006-08-27 15:10:09] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-08-27 15:10:09] WARN TCPServer Error: Bad file descriptor - bind(2)
c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `initialize': Bad file descriptor - bind(2) (Errno::EBADF)
from c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners'
from c:/ruby/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners'
from c:/ruby/lib/ruby/1.8/webrick/server.rb:75:in `listen'
from c:/ruby/lib/ruby/1.8/webrick/server.rb:63:in `initialize'
from c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize'
from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:59:in `dispatch'
from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/server:3

I realised that if I started the server on a different port, it worked (although I can't see how the error relates to this) e.g.
ruby script/server -p8000
Sometimes even restarting the computer doesn't solve the problem. Something must be running on port 3000 somtimes, but I can't figure out what! At least using a different port for my server lets me continue working.

UPDATE: See my next post for a way to get round this problem.



Digg Technorati del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

Please also visit the Swirrl blog

5 comments:

None said...

Thanks for the help - this solved my problem also. I just picked a different port and all was well again.

Anonymous said...

Picking a different port worked for me too. I wonder what is causing this...

Firewall issue perhaps?

Richard Roberts said...

Glad it solved it for you. For me it was caused by my PDA being in its dock. (See the subsequent post).

Luke said...

LOL! I did have a WinCE based handheld in the cradle and ActiveSync running at the time. Nice catch!

Gishu said...

In my case, it was a case of incorrect port configuration in database.yml i.e. 3307 instead of 3306. Changing it and restarting the web server solved my issue.
Seems to be a generic error when it is unable to talk to a specific port.