# TransactionError

**URL:** <https://www.ruby-forum.com/t/transactionerror/133892>\
**Category:** Rails\
**Created:** [April 4, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/transactionerror/133892 "2008-04-04T18:10:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobi\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@Tobi\_R](https://www.ruby-forum.com/u/Tobi_R)\
**Post date:** [April 4, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/transactionerror/133892/1 "2008-04-04T18:10:02Z")

</div>

Hi

Today I got an alert mail from my watcher script, telling me that there  
was no  
Mongrel running, and that it started one (so the site was down for a few  
seconds.)

This is the first time I got this error (AFAICS), but I’d like to  
resolve and  
prevent it for the future.

From mongrel.log:

\*\* Starting Mongrel listening at 0.0.0.0:foo  
\*\* Starting Rails with production environment…  
\*\* Rails loaded.  
\*\* Loading any Rails specific GemPlugins  
\*\* Signals ready. TERM =\> stop. USR2 =\> restart. INT =\> stop (no  
restart).  
\*\* Rails signals registered. HUP =\> reload (without restart). It might  
not work well.  
\*\* Mongrel available at 0.0.0.0:foo  
\*\* Writing PID file to  
/home/foo/skatestuff\_freebox/releases/20080319193713/tmp/pids/dispatch.foo.pid  
/home/foo/skatestuff\_freebox/releases/20080319193713/vendor/rails/activerecord/lib/active\_record/transactions.rb:76:in  
`transaction': Transaction aborted (ActiveRecord::Transactions::TransactionError) from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in `call’  
from  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in  
`join' from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in `join’  
from  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in  
`each' from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in `join’  
from  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:136:in  
`run' from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run’  
from  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:243  
from /usr/local/bin/mongrel\_rails:16:in `load’  
from /usr/local/bin/mongrel\_rails:16

“Transaction aborted” is in  
activerecord/lib/active\_record/transactions.rb:

module ClassMethods  
def transaction(&block)  
previous\_handler = trap(‘TERM’) { raise TransactionError,  
“Transaction aborted” }  
increment\_open\_transactions

```
  begin
    connection.transaction(Thread.current['start_db_transaction'], 

```

&block)  
ensure  
decrement\_open\_transactions  
trap(‘TERM’, previous\_handler)  
end  
end  
[…]

Above this, there’s  
“Both Base#save and Base#destroy come wrapped in a transaction […]”  
and  
“Also have in mind that exceptions thrown within a transaction block  
will be  
propagated […], so you should be ready to catch those in your  
application  
code.”

The site is not public yet (there still is a site-wide password), so I  
can be  
quite sure that there was no save or destroy called in my app code.

(By the way, in config/environments/production.rb I have

config.log\_level = :warn

but the error was not logged in log/production.log .

And in in config/environment.rb I have

config.action\_controller.session\_store = :active\_record\_store  
)

Could it be that the error occured when some session data was saved?

In actionpack/lib/action\_controller/session/active\_record\_store.rb there  
is

def update  
if @session  
ActiveRecord::Base.silence { @session.save }  
end  
end

The “silence” part would explain why there is no error message in  
the production.log .

Not sure whether I’m on the right track …

Anyways: How to prevent this error in the future?

Tobi

–  
[http://www.rubynaut.com/](http://www.rubynaut.com/)

---

<div class="post-metadata">

**Author:** ![Tobi\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@Tobi\_R](https://www.ruby-forum.com/u/Tobi_R)\
**Post date:** [April 8, 2008, 10:59am UTC](https://www.ruby-forum.com/t/transactionerror/133892/2 "2008-04-08T10:59:09Z")

</div>

Hi

Any idea how to prevent this error?

Tobi

On Fri 2008-04-04 Tobi R. wrote:

> transaction’: Transaction aborted (ActiveRecord::Transactions::TransactionError)
> 
> ```
> decrement_open_transactions
> 
> ```
> 
> code."  
> And in in config/environment.rb I have  
> ActiveRecord::Base.silence { @session.save }  
> Tobi
> 
> –  
> [http://www.rubynaut.com/](http://www.rubynaut.com/)

–  
[http://www.rubynaut.com/](http://www.rubynaut.com/)

---

<div class="post-metadata">

**Author:** ![Tobi\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@Tobi\_R](https://www.ruby-forum.com/u/Tobi_R)\
**Post date:** [April 8, 2008, 11:39am UTC](https://www.ruby-forum.com/t/transactionerror/133892/3 "2008-04-08T11:39:48Z")

</div>

On 8 Apr 2008, at 09:59, Tobi R. wrote:

> > Today I got an alert mail from my watcher script, telling me that  
> > there was no  
> > Mongrel running, and that it started one (so the site was down for  
> > a few  
> > seconds.)
> > 
> > This is the first time I got this error (AFAICS), but I’d like to  
> > resolve and  
> > prevent it for the future.

Can you figure out from your logs what your server was doing when this  
happened? Could anything else have sent a TERM signal to your mongel  
(eg something that kills processes if they are using excessive memory?

Fred
