You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Richard F. Rebel" <rr...@whenu.com> on 2005/10/14 23:32:47 UTC

PerlCleanupHanlder not called when user clicks on STOP in browser.

Hello,

I have been noticing that PerlCleanupHandlers are not called when a user
pressed the STOP button in their browser before the page is downloded.

Is this normal behavior or a bug?

I really need my handler to run no matter what if possible, at the end
of the cycle.  Is there a way to achieve this?

Thanks!

-- 
Richard F. Rebel

cat /dev/null > `tty`

Re: PerlCleanupHanlder not called when user clicks on STOP in browser.

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2005-10-17 at 11:45 -0400, Richard F. Rebel wrote:
> DBG is an already open auto-flushed file handle.  The AuthzHandler
> prints to it, other invocations of cleanup handler print to it, and only
> when user presses stop do we not ever the output from this line.

I suggest you print to STDERR instead, or call Apache2::Log directly
($r->log_error).

> If it's segfaulting, wouldn't there be a log of this in apache's error
> log?

I would expect so.  Have you checked to see if the process ID is still
running after this happens?  Maybe it's just hanging, rather than
actually exiting, and never makes it to your cleanup handler.

> BTW, this is mod_perl2.

Okay, the handling for aborted connections is still the same.  You will
find the aborted() method in Apache2::Connection.

- Perrin


Re: PerlCleanupHanlder not called when user clicks on STOP in browser.

Posted by "Richard F. Rebel" <rr...@whenu.com>.
On Mon, 2005-10-17 at 11:31 -0400, Perrin Harkins wrote:

> It sounds like you're jumping to conclusions to me.  The cleanup handler
> does execute, even when the user presses stop, unless something
> catastrophic  is happening like an actual segfault.
> 
> My guess would be that something is going wrong with your MySQL code in
> the cleanup handler.  I would put some debug information in there to see
> if the cleanup runs and see if it is trying to run the query.  You could
> also turn on tracing, or run it in the debugger.

This is the first thing I did.  The first line of my cleanup handler is:

print DBG scalar(localtime), " ", __PACKAGE__, "CleanupHanlder started
\n";

DBG is an already open auto-flushed file handle.  The AuthzHandler
prints to it, other invocations of cleanup handler print to it, and only
when user presses stop do we not ever the output from this line.

If it's segfaulting, wouldn't there be a log of this in apache's error
log?

BTW, this is mod_perl2.


> > Also, where in the docs are you talking about in your message below.
> 
> Right here:
> http://perl.apache.org/docs/1.0/guide/debug.html#Handling_the__User_pressed_Stop_button__case
> 
> - Perrin
> 
-- 
Richard F. Rebel

cat /dev/null > `tty`

Re: PerlCleanupHanlder not called when user clicks on STOP in browser.

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2005-10-17 at 11:16 -0400, Richard F. Rebel wrote:
> When a user starts a program which takes a few seconds to run, and you
> hit the stop button, then start another, the user is denied, which is
> correct behavior.  The problem is that the lock is never removed as the
> cleanup handler never executes.

It sounds like you're jumping to conclusions to me.  The cleanup handler
does execute, even when the user presses stop, unless something
catastrophic  is happening like an actual segfault.

My guess would be that something is going wrong with your MySQL code in
the cleanup handler.  I would put some debug information in there to see
if the cleanup runs and see if it is trying to run the query.  You could
also turn on tracing, or run it in the debugger.

> Also, where in the docs are you talking about in your message below.

Right here:
http://perl.apache.org/docs/1.0/guide/debug.html#Handling_the__User_pressed_Stop_button__case

- Perrin


Re: PerlCleanupHanlder not called when user clicks on STOP in browser.

Posted by "Richard F. Rebel" <rr...@whenu.com>.
Maybe some more information would be useful here.

We have a couple hundred old reporting CGI's.  We have a bunch of users
whom sometimes think they run too slow so either it the stop button on
the browser, or they are the type to double click on buttons or links
causing multiple copies to run.

The programs usually only take about 5 or 10 seconds to run, but
sometimes as long as a minute.

I wrote a Authz handler which basically makes sure they don't have more
than x copies of the program already running.  It does this via checking
a configuration table in mysql which has a max per user setting for each
uri path, then checking another table containing locks.  Either the user
is forbidden, or lock is written to the db and the handler returns OK.

A cleanup handler is used to remove the locks from the database.

When a user starts a program which takes a few seconds to run, and you
hit the stop button, then start another, the user is denied, which is
correct behavior.  The problem is that the lock is never removed as the
cleanup handler never executes.  The PID of the process which creates a
lock in the database is stored, and upon investigation the PID is never
in the process list.

So, this means what?  I guess apache died before cleanup handler is
run???  There is nothing in the error logs.  Why would hitting the stop
button cause apache to die without running the cleanup handler?

Also, where in the docs are you talking about in your message below.  I
dug around but didn't find anything.  A quick note about rough location
or something to search for would be great.

Thanks.

On Fri, 2005-10-14 at 17:35 -0400, Perrin Harkins wrote:
> On Fri, 2005-10-14 at 17:32 -0400, Richard F. Rebel wrote:
> > I have been noticing that PerlCleanupHandlers are not called when a user
> > pressed the STOP button in their browser before the page is downloded.
> 
> Yes it is, but not until the request is actually completed.  If you want
> to stop your handler from trying to continue the request if the
> connection has been cut, there is info in the docs on how to do that.
> 
> - Perrin
> 
-- 
Richard F. Rebel

cat /dev/null > `tty`

Re: PerlCleanupHanlder not called when user clicks on STOP in browser.

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2005-10-14 at 17:32 -0400, Richard F. Rebel wrote:
> I have been noticing that PerlCleanupHandlers are not called when a user
> pressed the STOP button in their browser before the page is downloded.

Yes it is, but not until the request is actually completed.  If you want
to stop your handler from trying to continue the request if the
connection has been cut, there is info in the docs on how to do that.

- Perrin