Wednesday, March 21, 2007

 

Ruby on Rails : Mongrel cannot start in production mode with plugins

This problem has been annoying me for a whole night, hope that i can share these with you guys and save others time in deploying their rails app.

Problem:

My problem occur while i was trying to deploy the apps on a Ubuntu 6.06 (X86_64) on a Xeon machine.

After deployed the apps to this server, my app run smoothly in development mode, but whenever i want to start the webrick/mongrel in production mode, it hits the segmentation fault. It was scary... it was the 1st time i saw "segmentation fault" after i graduated from my university....

Troubleshooting Details:
(** for those dont want to know the details and would like quick solution skip this part)

I tried to do the same on development server which was an i386 machine, it doesn't repro, so i conclude it only happen in x86_64 machine, as i got my dev machine in nearly the same setting except it is i386 machine, which i can get the webrick/mongrel started smoothly in production.

Then i tried to trace the code by the "segmentation fault" error, which pointed me to the Line 99 of :
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb
I narrowed down the problem into the line of code:

Dir[glob].select { |f| File.file?(f) }.empty?


where i traced it hits error when:
glob = "/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/{lib,bin}/rails/technoweenie{,.rb,.so,.bundle,.dll,.sl}"

i can repro this in "script/console", i feel puzzled, it seems like a simple search in directories.. i can't imagine whats going on there leading to segmentation fault...

Anyhow, i concoluded that it is somewhat related to my plugins from technoweenie, which is the "act_as_attachment" plugin, so i tried to remove plugins 1 by 1 and finally figured out there was 2 plugin which can both cause the problem individually, the other one is "calender_helper"

So i got frustrated again even i sorted out the source of problem... since my code somehow depends on these 2 plugin.. then, some more time are spent on Google, i finally tackled it without rewriting my code.

Solution:

Run a single line in the app directory:

rake rails:freeze:gems


It some how copied the rails code into the vender directory, and it seems that the problem has been solved, i can now start the mongrel in production mode smoothly.. Yeah~


Question:

Actually i am still puzzled why doing the "rake rails:freeze:gems" solved the problem, coz i am not quite sure what it does except copying the files.

On the other hand, the error seems to be thrown by a very primitive function of ruby
Dir[glob].select { |f| File.file?(f) }.empty?

I wonder if this is a ruby bug on x86_64 machine.... increased my fear in deploying the app on x86_64 ....


Server Config:
Xeon 3040
Ubuntu 6.06 (x86_64)

$>ruby -v
ruby 1.8.4 (2005-12-24) [x86_64-linux]
$>rails -v
Rails 1.1.6
$>gem -v
0.8.11

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?