Today, the Rails team finally released the first beta of Rails 3. Trying to play around with it, I experienced a very annoying problem with mongrel:

Per default, Rails seems to only work with the gems listed in its Gemfile, which means that it starts using webrick. I wanted it to use mongrel, like Rails 2 does and added gem "mongrel" to my gemfile which resulted in rails server just freezing. The cuplrit was some of the weirdest piece of code I’ve ever seen, mongrel’s Mongrel::Gems.require function:

def require(library, version = nil)
  begin
    Kernel.require library
  rescue LoadError, RuntimeError => e
    begin 
      # ActiveSupport breaks 'require' by making it always return a true value
      Kernel.require 'rubygems'
      version ? gem(library, version) : gem(library)
      retry
    rescue Gem::LoadError, LoadError, RuntimeError
      # puts "** #{library.inspect} could not be loaded" unless library == "mongrel_experimental"
    end
  end  
end

An infinite loop with the only way out being an exception that never got thrown!

This madness was called from mongrel.rb:

$LOAD_PATH.unshift 'projects/mongrel_experimental/lib/'
Mongrel::Gems.require 'mongrel_experimental', ">=#{Mongrel::Const::MONGREL_VERSION}"

Removing these two lines solved the issue. That would have meant patching my gems however, and that smells like something you should not do. The final solution was simple and posted in the comments of the Rails 3 Beta announcement by Juanma Cervera. I just needed to add 3 more lines to my Gemfile:

gem "mongrel"
gem "cgi_multipart_eof_fix"
gem "fastthread"
gem "mongrel_experimental"