# Selectively failing when mongrel restarted with monit \[was:

**URL:** <https://www.ruby-forum.com/t/selectively-failing-when-mongrel-restarted-with-monit-was/91223>\
**Category:** Deployment\
**Created:** [April 5, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/selectively-failing-when-mongrel-restarted-with-monit-was/91223 "2007-04-05T19:38:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwt137](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7c8e57/32.png) [@cwt137](https://www.ruby-forum.com/u/cwt137)\
**Post date:** [April 5, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/selectively-failing-when-mongrel-restarted-with-monit-was/91223/1 "2007-04-05T19:38:17Z")

</div>

OK. Made a bit of progress on this. Have setup a duplicate server  
instance with mongrel\_cluster on it (really glad I went with Xen now)  
and also done a bit of following back the code with ruby-debug.  
I can now reproduce the error, but only if I (re)start the mongrels with  
monit. Then, the particular page fails every time. Here’s the particular  
part of the montirc file that restarts the mongrel instances:

```
check process mongrel_8001 with pidfile
/var/run/mongrel_cluster/mongrel_carstuff.8001.pid
  start program = "/usr/bin/mongrel_rails cluster::start -C
/home/frankg/sites/carstuff/current/config/mongrel_cluster.yml
--clean --only 8001"
  stop program = "/usr/bin/mongrel_rails cluster::stop -C
/home/frankg/sites/carstuff/current/config/mongrel_cluster.yml
--clean --only 8001"

```

However, if I manually start a mongrel instance with:  
/usr/bin/mongrel\_rails cluster::start -C  
/home/frankg/sites/carstuff/current/config/mongrel\_cluster.yml --clean  
–only 8001  
the page is rendered with no problems.

Couple of other things, What seemed to be happening on that page was  
that the Photo model was being reloaded, as if it was in the development  
environment. It fails the first time (ImageScience fails on the line env  
= ENV[‘INLINEDIR’] || ENV[‘HOME’] – both are nil). Why it occurs on  
that page and not on others, I still haven’t figured out.

Will keep plugging away at this, but if anyone’s got any bright ideas  
would welcome them.

Thanks  
Chris

-------- Original Message --------  
From: - Wed Apr 04 18:25:04 2007  
X-Mozilla-Status: 0001  
X-Mozilla-Status2: 00800000  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Wed, 04 Apr 2007 18:25:02 +0100  
From: Chris T [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: removed\_email\_address@domain.invalid  
User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221)  
MIME-Version: 1.0  
To: removed\_email\_address@domain.invalid  
Subject: Suggestions needed for strange problem on only one mongrel  
instance out of cluster  
Content-Type: text/plain; charset=ISO-8859-1; format=flowed  
Content-Transfer-Encoding: 7bit

I’m about to release my app (was going to today), but have found a last  
minute bug that I’m have difficulty tying down, never mind fix. It’s  
occurring sporadically, and is fixed (temporarily) by restarting the  
instance of the mongrel, but is not always caused by the same page.  
Honestly, I’m not sure I know where to start trying to track it down,  
and any help would be appreciated.

What’s happening is this. If I hit one particular page (have observed  
this on only two pages so far but of course may affect others) with  
photos on it a number of times it renders fine (the photos are linked to  
the model via attachment\_fu, which is using Image Science, not RMagick).

Then suddenly, it blows up, with one of two errors. The first error is  
the following (can post full stack trace if anyone thinks it’s useful):

A ActionView::TemplateError occurred in modtypes#show:

exit  
On line #1 of app/views/shared/\_main\_photo.rhtml

1: \<% if main\_photo.medium\_image\_url %\>  
2:

  
3: \<%= link\_to image\_tag(main\_photo.medium\_image\_url, {:alt =\>  
main\_photo.title, :title =\> main\_photo.caption}), photo\_path(main\_photo)  
%\>  
4: 
\<%= link\_to(  
truncate(main\_photo.caption,80, “… see more”), photo\_path(main\_photo))  
if main\_photo.caption %\>

/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:70:in `exit' /usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:70:in `rootdir’  
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:84:in  
`directory' /usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:257:in `so\_name’  
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:291:in  
`load_cache' /usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:627:in `inline’  
/usr/lib/ruby/gems/1.8/gems/image\_science-1.1.1/lib/image\_science.rb:84  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:32:in  
`gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:32:in `require’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:496:in  
`require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:343:in `new\_constants\_in’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:496:in  
`require' #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb:1 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:343:in  
`new_constants_in' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:105:in  
`require_or_load' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:249:in `load\_missing\_constant’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:453:in  
`const_missing' #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:82:in `const\_get’  
#{RAILS\_ROOT}/vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:82:in  
`has_attachment' #{RAILS_ROOT}/app/models/photo_image.rb:8 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:343:in  
`new_constants_in' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:105:in  
`require_or_load' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:249:in `load\_missing\_constant’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:453:in  
`const_missing' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in `const\_missing’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/base.rb:1355:in  
`compute_type' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/reflection.rb:125:in `send’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/reflection.rb:125:in  
`klass' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/reflection.rb:129:in `table\_name’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/associations/has\_one\_association.rb:74:in  
`construct_sql' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations/has_one_association.rb:6:in `initialize’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/associations.rb:882:in  
`new' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:882:in `photo\_image’  
#{RAILS\_ROOT}/app/models/photo.rb:45:in `medium_image_url' #{RAILS_ROOT}/app/views/shared/_main_photo.rhtml:1:in `\_run\_rhtml\_47app47views47shared47\_main\_photo46rhtml’

Then if the same instance is hit again it returns a slightly different  
error:

A ActionView::TemplateError occurred in modtypes#show:

Expected  
/home/frankg/sites/carstuff/current/config/…/app/models/photo\_image.rb  
to define PhotoImage  
On line #1 of app/views/shared/\_main\_photo.rhtml

1: \<% if main\_photo.medium\_image\_url %\>  
2:

  
3: \<%= link\_to image\_tag(main\_photo.medium\_image\_url, {:alt =\>  
main\_photo.title, :title =\> main\_photo.caption}), photo\_path(main\_photo)  
%\>  
4: 
\<%= link\_to(  
truncate(main\_photo.caption,80, “… see more”), photo\_path(main\_photo))  
if main\_photo.caption %\>

#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:250:in  
`load_missing_constant' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in `const\_missing’  
#{RAILS\_ROOT}/vendor/rails/activesupport/lib/active\_support/dependencies.rb:465:in  
`const_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1355:in `compute\_type’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/reflection.rb:125:in  
`send' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/reflection.rb:125:in `klass’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/reflection.rb:129:in  
`table_name' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations/has_one_association.rb:74:in `construct\_sql’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/associations/has\_one\_association.rb:6:in  
`initialize' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:882:in `new’  
#{RAILS\_ROOT}/vendor/rails/activerecord/lib/active\_record/associations.rb:882:in  
`photo_image' #{RAILS_ROOT}/app/models/photo.rb:45:in `medium\_image\_url’  
#{RAILS\_ROOT}/app/views/shared/\_main\_photo.rhtml:1:in  
`\_run\_rhtml\_47app47views47shared47\_main\_photo46rhtml’

While all this is going on, the other mongrel instances are serving up  
the page with no probs. I’m running Ruby 1.8.5 with Rails 1.2.1  
(frozen), on a number of Xen instances running Debian etch.

The page above is simply a ‘show’ page. There’s no dynamic resizing of  
photos, or anything like that (so not sure why Image Science is being  
invoked in the first error). It’s a really very straightforward page  
from a controller/view perspective.

If anyone has any ideas, or point me towards a strategy for tracking  
down the problem, I’d be very grateful.  
Many thanks  
Chris

---

<div class="post-metadata">

**Author:** ![cwt137](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7c8e57/32.png) [@cwt137](https://www.ruby-forum.com/u/cwt137)\
**Post date:** [April 5, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/selectively-failing-when-mongrel-restarted-with-monit-was/91223/2 "2007-04-05T20:55:28Z")

</div>

Chris-

On Apr 5, 2007, at 10:37 AM, Chris T wrote:

> ```
> check process mongrel_8001 with pidfile
> 
> ```
> 
> /home/frankg/sites/carstuff/current/config/mongrel\_cluster.yml --clean
> 
> Will keep plugging away at this, but if anyone’s got any bright ideas  
> would welcome them.
> 
> Thanks  
> Chris

Monit starts your mongrels with a fully clean environemnt. Meaning  
none of your normal ENV vars are set. WHat you need to do is put this  
in the top of your environment.rb

ENV[‘HOME’] = “/home/foobar”

Then restart monit and all the mongrels. This will fix the problem.

Cheers-

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![cwt137](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7c8e57/32.png) [@cwt137](https://www.ruby-forum.com/u/cwt137)\
**Post date:** [April 5, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/selectively-failing-when-mongrel-restarted-with-monit-was/91223/3 "2007-04-05T21:04:29Z")

</div>

Ezra Z. wrote:

> > monit. Then, the particular page fails every time. Here’s the  
> > –clean --only 8001"  
> > environment. It fails the first time (ImageScience fails on the
> 
> Cheers-

Ezra  
Thanks so much for this. Much appreciated.  
Chris
