fixing webrick error – WARN TCPServer Error: Bad file descriptor – bind(2) – on windows

I was working on a Ruby on Rails project with Netbeans today when I went to fire up webbrick to test something in the app.

I immediately got an error like this

=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
[2008-03-18 16:36:59] INFO  WEBrick 1.3.1
=> Ctrl-C to shutdown server; call with --help for options
[2008-03-18 16:36:59] INFO  ruby 1.8.6 (2007-03-13) [i386-mswin32]
[2008-03-18 16:36:59] 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 `new'
        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 `each'
        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.2.3/lib/webrick_server.rb:58:in `new'
         ... 7 levels...
        from C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from script/server:3

I did a quick google of the error, and the general consensus was that something was blocking port 3000.
But when I used the “netstat” command at the command line, I didn’t see anything on the port …

netstat command

I was scratching my head a bit, but I went in to look at what processes were running and I discovered this ruby process …

ruby process in windows

Remember, webrick wasn’t running at this point, because it kept erroring out.
I figured that this was my problem, and on further prodding with Process Explorer, I found …

ruby process blocking port 3000

So I just killed the process and all was well with the universe 🙂

webrick works again