You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Michael Peppler <mp...@peppler.org> on 2000/08/09 17:42:32 UTC

PerlCleanupHandler

Hi,

We're seeing a number of requests where the write from apache to the
client browser times out and the SIGALRM signal fires. Our
Apache::Registry scripts in that case don't clean up correctly,
leaving session lock files around, which of course causes that
particular session to be screwed up for a while.

My question is would a Cleanup handler still be called in this case?

( I'm asking because it's a large site, and I can't just add code left
and right... :-) 

Thanks!

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com

Re: PerlCleanupHandler

Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 11 Aug 2000, Tim Sweetman wrote:
 
> I've seen something similar - when the client browser times out,
> execution seems to stop mid-Print statement, and mod_Perl gets ready for
> the next request, without cleaning up objects present (or, at least,
> without calling ->DESTROY).

this should be fixed with the hard_timeout -> soft_timeout change.
 
> IIRC, "END" blocks are called by mod_Perl, rather than Perl itself,
> since Perl normally calls them only when the interpreter is about to
> shut down. END blocks still get called in this situation, so if you run
> foo.pl and manage to hit stop before it's printed its output...

right, because mod_perl runs Apache::Registry END blocks in a cleanup.
 
> More disturbingly, there seem to be very occasional cases where the
> cleanup stuff doesn't do what's expected of it, so I suggest you keep an
> eye on what's happening. Our current workaround - not a good one - is to
> kill $$ when objects don't get cleaned up correctly.

hmm, the hard_timeout() may have left Perl in a confused state.  if you're
still seeing this behavior with the soft_timeout() change, i'd appreciate
any details you have on this.


Re: PerlCleanupHandler

Posted by Tim Sweetman <ti...@aldigital.co.uk>.
Hi,

Michael Peppler wrote:
> We're seeing a number of requests where the write from apache to the
> client browser times out and the SIGALRM signal fires. Our
> Apache::Registry scripts in that case don't clean up correctly,
> leaving session lock files around, which of course causes that
> particular session to be screwed up for a while.
> 
> My question is would a Cleanup handler still be called in this case?
> 
> ( I'm asking because it's a large site, and I can't just add code left
> and right... :-)

I've seen something similar - when the client browser times out,
execution seems to stop mid-Print statement, and mod_Perl gets ready for
the next request, without cleaning up objects present (or, at least,
without calling ->DESTROY).

IIRC, "END" blocks are called by mod_Perl, rather than Perl itself,
since Perl normally calls them only when the interpreter is about to
shut down. END blocks still get called in this situation, so if you run
foo.pl and manage to hit stop before it's printed its output...

my $object = new Foo::Bar;
# blah blah blah
print "The answer is ", $object->answer;

sub END { warn "bye!\n" };

and in Bar.pm
sub DESTROY { warn "outta here!\n" };

... you get "bye!" in the error log, but not "outta here!".

This obviously plays merry hell with database handles on transactioned
databases, session locks, etc.

I don't know for sure if SIGALRM is involved in this, though that seems
plausible.

My guess is that if END gets called, so will a cleanup handler.

More disturbingly, there seem to be very occasional cases where the
cleanup stuff doesn't do what's expected of it, so I suggest you keep an
eye on what's happening. Our current workaround - not a good one - is to
kill $$ when objects don't get cleaned up correctly.

Hope this helps...

--
Tim Sweetman
A L Digital
"When in Rome, burn it!"

Re: PerlCleanupHandler

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 9 Aug 2000, Michael Peppler wrote:

> Hi,
> 
> We're seeing a number of requests where the write from apache to the
> client browser times out and the SIGALRM signal fires. Our
> Apache::Registry scripts in that case don't clean up correctly,
> leaving session lock files around, which of course causes that
> particular session to be screwed up for a while.
> 
> My question is would a Cleanup handler still be called in this case?

yes.  but, the proper solution is for mod_perl to change usage of
hard_timeout() to soft_timeout().  hard_timeout() does a longjmp out to
the accept loop, whereas soft_timeout() just sets $r->connection->aborted
to 1, so all apache i/o calls become noops, but the script continues to
run until finished.  i don't know why we used hard_timeout() in the first
place.  if a script wants to abort, they'll need to do it themselves,
something along the lines of:

$r->print('foo');
die if $r->connection->aborted;

Index: Apache/Apache.pm
===================================================================
RCS file: /home/cvs/modperl/Apache/Apache.pm,v
retrieving revision 1.52
diff -u -r1.52 Apache.pm
--- Apache/Apache.pm	2000/08/15 04:35:13	1.52
+++ Apache/Apache.pm	2000/08/31 05:38:36
@@ -68,7 +68,7 @@
     $_[1] ||= "";
     #$_[1] = " " x $bufsiz unless defined $_[1]; #XXX?
 
-    $r->hard_timeout("Apache->read");
+    $r->soft_timeout("Apache->read");
 
     while($bufsiz) {
 	$nrd = $r->read_client_block($buf, $bufsiz) || 0;
@@ -113,7 +113,7 @@
 	return 0;
     }
 
-    $r->hard_timeout("Apache->read");
+    $r->soft_timeout("Apache->read");
     
     while($bufsiz) {
 	$nrd = $r->get_client_block($buf, $bufsiz) || 0;
@@ -425,7 +425,7 @@
 looping until it gets all of C<$bytes_to_read> or a timeout happens.
 
 In addition, this method sets a timeout before reading with
-C<$r-E<gt>hard_timeout>.
+C<$r-E<gt>soft_timeout>.
 
 =item $r->get_remote_host
 
@@ -909,7 +909,7 @@
 =item $r->print( @list )
 
 This method sends data to the client with C<$r-E<gt>write_client>, but first
-sets a timeout before sending with C<$r-E<gt>hard_timeout>. This method is
+sets a timeout before sending with C<$r-E<gt>soft_timeout>. This method is
 called instead of CORE::print when you use print() in your mod_perl programs.
 
 This method treats scalar references specially. If an item in @list is a
Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.105
diff -u -r1.105 Apache.xs
--- src/modules/perl/Apache.xs	2000/08/31 03:39:45	1.105
+++ src/modules/perl/Apache.xs	2000/08/31 05:38:48
@@ -1033,7 +1033,7 @@
     }
     else {
 	CV *cv = GvCV(gv_fetchpv("Apache::write_client", FALSE, SVt_PVCV));
-	hard_timeout("mod_perl: Apache->print", r);
+	soft_timeout("mod_perl: Apache->print", r);
 	PUSHMARK(mark);
 #ifdef PERL_OBJECT
 	(void)(*CvXSUB(cv))(cv, pPerl); /* &Apache::write_client; */