# ActiveRecord write stops script from responding to SIGTERM

**URL:** <https://www.ruby-forum.com/t/activerecord-write-stops-script-from-responding-to-sigterm/97028>\
**Category:** Rails\
**Created:** [July 4, 2006, 11:28am UTC](https://www.ruby-forum.com/t/activerecord-write-stops-script-from-responding-to-sigterm/97028 "2006-07-04T11:28:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@fcheung](https://www.ruby-forum.com/u/fcheung)\
**Post date:** [July 4, 2006, 11:28am UTC](https://www.ruby-forum.com/t/activerecord-write-stops-script-from-responding-to-sigterm/97028/1 "2006-07-04T11:28:10Z")

</div>

We’ve got a small daemon we run on our servers, which looks something  
like this

require File.dirname( **FILE** ) + ‘/…/config/boot’  
require File.dirname( **FILE** ) + ‘/…/config/environment’

ActiveRecord::Base.establish\_connection

do  
m = Message.next\_pending  
if m  
m.do\_something  
else  
sleep 5  
end  
end

Stuff gets place in this queue through other interactions with our web  
application and this guy processes them. This part all works fine.  
The problem is when we try and stop the daemon running by sending a  
SIGTERM. If the daemon never found any message to process it exits fine,  
but if it did then it doesn not respond to the sigterm and we have to  
kill -9 it.

After a bit of investigation we found that our process would respond to  
SIGTERM properly as long as we had not done any ActiveRecord writes  
(reading from the database is fine). However as soon as we do an update  
or a create then the process stops responding to the SIGTERMs. It does  
however continue to run properly, and will find and process any new  
messages

This is running on an x86 linux machine (rails 1.1.2), anmd we’re using  
mysql 4.1  
I’m rather at a loss to explain this behaviour, anyone have any ideas

Thanks,

Fred

---

<div class="post-metadata">

**Author:** ![fcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@fcheung](https://www.ruby-forum.com/u/fcheung)\
**Post date:** [July 4, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/activerecord-write-stops-script-from-responding-to-sigterm/97028/2 "2006-07-04T22:24:42Z")

</div>

Hi-

On Jul 4, 2006, at 2:28 AM, Frederick C. wrote:

> if m  
> fine,  
> messages
> 
> This is running on an x86 linux machine (rails 1.1.2), anmd we’re  
> using  
> mysql 4.1  
> I’m rather at a loss to explain this behaviour, anyone have any ideas
> 
> Thanks,
> 
> Fred

Fred-

```
I'm not entirely sure why your daemon stops responding after a db

```

write. But you could convert your daemon over to use my BackgrounDRb  
plugin[1] which was written for situations exactly like what you are  
doing here.

Check it out here:

\*Home page: [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)  
\*svn repo: svn://rubyforge.org//var/svn/backgroundrb  
\*Mailing list: [http://rubyforge.org/mailman/listinfo/backgroundrb-devel](http://rubyforge.org/mailman/listinfo/backgroundrb-devel)

-Ezra
