Frederick Cheung
2006-Jul-04 09:28 UTC
[Rails] ActiveRecord write stops script from responding to SIGTERM
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
--
Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-04 20:22 UTC
[Rails] ActiveRecord write stops script from responding to SIGTERM
Hi- On Jul 4, 2006, at 2:28 AM, Frederick Cheung wrote:> 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, > > FredFred- 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 *svn repo: svn://rubyforge.org//var/svn/backgroundrb *Mailing list: http://rubyforge.org/mailman/listinfo/backgroundrb-devel -Ezra -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060704/93d57ee7/attachment-0001.html
Possibly Parallel Threads
- [PATCH] lib: direct, uml: Unblock SIGTERM in the hypervisor and recovery processes (RHBZ#1460338).
- [PATCH] ssh-agent: exit 0 from SIGTERM under systemd socket-activation
- Why doesn't SIGTERM quit gracefully?
- [Bug 1029] SIGTERM and cleanup of wtmp files
- [Bug 3531] New: Ssh will not exit when it receives SIGTERM before calling poll in client_wait_until_can_do_something until some events happen.