[Catalyst] Proper way to perform cleanups on server shutdown?

John Napiorkowski jjn1056 at yahoo.com
Wed Jul 11 17:03:29 GMT 2007


--- Matt S Trout <dbix-class at trout.me.uk> wrote:

> On Wed, Jun 27, 2007 at 02:38:34PM -0700, John
> Napiorkowski wrote:
> > Hi,
> > 
> > I'm finding that the way I usually catch shutdown
> > signals to perform cleanup is not working. 
> Setting
> > %SIG handlers doesn't seem to do it and I'm not
> > finding that DESTROY methods are getting fired off
> in
> > the expected way.
> > 
> > For example if I set a $SIG{INT} handler in the
> > application class (MyApp.pm) that get's called if
> I am
> > running the development server foregrounded and
> the
> > interrupt it with a 'ctrl-c', but it doesn't get
> > called if the development server is deamonized and
> I
> > kill the process.  $SIG{QUIT} doesn't seem to do
> it. 
> > DESTROY doesn't seem to every get called.
> 
> Add some better traces - I suspect this is either
> (a) a DBIC problem fixed
> in 0.08 or (b) a problem that isn't that you didn't
> give us a test case for
> yet :)

Okay, I've got something strange and could use some
advice about the best way to create a test case for
it.

Basically I am finding that END blocks anywhere in a
Catalyst application (even in END blocks from included
libraries) never get called when running the standard
development server and then shutting it down with
either an INT or TERM.

INT get's generated if you are running the development
server forgrounded and then press 'ctrl-c' to exit it,
while I get a TERM signal when running the server
backgrounded and then using kill $pid on it.

I can demonstrate this by placing an END block in my
root modules (the "MyApp.pm" module)

END {
  print "got END BLOCK!\n";
}

This will never run under the conditions I have
described.

HOWEVER, if I set SIG handlers manually like so:

$SIG{INT} = sub { print "got INT!\n" };
$SIG{TERM} = sub { print "got TERM!\n" };

END {
  print "got END BLOCK!\n";
}

Then the END block does run.  It also runs everywhere
in any Catalyst package or included module.

I'm not sure if this affects the other Catalyst
Engines.  I'll try to test it on Apache, for example. 
But I'm a little perplexed by this.  I am guessing
that these SIG handlers are being set someplace that
is causing trouble with the END blocks and that when I
set them myself it clears that trouble.  My suspicion
of this is increased because if I set the SIG handlers
as local the trouble behavior returns.

I'm not so sure how to create a test for this, since
I'm not sure how to capture  these Signals and could
use some advice for that.  I Could also use some
thoughts from the group as to what we'd like for this
to do.  Ignoring all END blocks is not good!

Thanks!

John


       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  



More information about the Catalyst mailing list