Jul 12, 2011

Rails 3, RoutingError crashes the server

I have encountered this weird behavior. It took me 6 consecutive hours to solve it by debugging the whole Rails code.

In this post, someone suggests that we switch from WEBrick to Mongrel.

I have found out that the code piece which causes the problem is (It is located in C:\Ruby192\lib\ruby\gems\1.9.1\gems\railties-3.0.9\lib\rails\rack\log_tailer.rb):


module Rails
module Rack
class LogTailer
.
.
.

def tail!
@file.seek @cursor

if !@file.eof?
contents = @file.read
@cursor = @file.tell
$stdout.print contents
end
end
end
end
end


If you blank this method, WEBrick works fine again. I have done an intensive test on it with a lot of RoutingError thrown.

You can use this patch. Put it in the environment file:



module Rails
module Rack
class LogTailer

def tail!

end
end
end
end


The downside of this is that you won't see debug messages on your console.

To bypass this problem, you can use log4r to output debug messages on console instead.

Work like a charm for me.