ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

am 15.10.2002 13:01:33 von srp

Hello,

I have a mod_perl application which does a internal_redirect() and registers a
cleanup handler before returning. I am noticing that the cleanup handler
executes and i see the following in my log ..

[Tue Oct 15 03:27:32 2002] [info] [client XYZ ] (9)Bad file number: client
stopped connection before rvputs completed

* Why is apache trying to write to client during the cleanup phase ?

Further ...

Since the call is to ap_rvputs(), I assumed it is not a mod_perl issue. I
confirmed that the handler was 'default-handler' by asking ap_invoke_handler()
to log each invocation.

But when I forced the handler to be 'perl-script' by using
internal_redirect_handler(). This time I get

[Tue Oct 15 00:59:29 2002] [info] [client XYZ] (9)Bad file number: client
stopped connection before rwrite completed

I hacked ap_rvputs() & ap_rwrite() to not return on a write() failure but to log
the attempt. It seems that both want to write HTTP headers to client. ( I
confirmed that it is for the same request 'r->the_request')

Why is apache re-doing the request after a internal_redirect() ? ( and that too
in the cleanup phase ??)

Please help me understand this. Any hints most appreciated :-)

regards
srp

ps :: please reply to me directly as i am not on the list

Re: ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

am 15.10.2002 13:33:09 von cubic

Hello!

internal_redirect()
The required argument is an absolute URI path on the current server.
The server will process the URI as if it were a whole new request,
running the URI translation, MIME type checking, and other phases
before invoking the appropriate content handler for the new URI.
The content handler that eventually runs is not necessarily the same
as the one that invoked internal_redirect().
This method should only be called within a content handler.
That from "Writing Apache modules with Perl and C".
ssn> Hello,

ssn> Why is apache re-doing the request after a internal_redirect() ? ( and that too
ssn> in the cleanup phase ??)

ssn> Please help me understand this. Any hints most appreciated :-)
mailto:cubic@wr.miee.ru

Re: ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

am 15.10.2002 13:37:01 von cubic

Hello again.
May be it helps to solve your problem.
is_initial_req()

There are several instances in which an incoming URI request can
trigger one or more secondary internal requests. An internal request
is triggered when internal_redirect() is called explicitly, and it
also happens behind the scenes when lookup_file() and lookup_uri()
are called.

With the exception of the logging phase, which is run just once for
the primary request, secondary requests are run through each of the
transaction processing phases, and the appropriate handlers are
called each time. There may be times when you don't want a
particular handler running on a subrequest or internal redirect,
either to avoid performance overhead or to avoid infinite recursion.
The is_initial_req() method will return a true value if the current
request is the primary one and false if the request is the result of
a subrequest or an internal redirect.

return DECLINED unless $r->is_initial_req;

ssn> Hello,

ssn> Why is apache re-doing the request after a internal_redirect() ? ( and that too
ssn> in the cleanup phase ??)

ssn> Please help me understand this. Any hints most appreciated :-)
mailto:cubic@wr.miee.ru

Re: ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

am 15.10.2002 13:48:56 von srp

Thanks for reply ..

> Hello!
>
> internal_redirect()
> The required argument is an absolute URI path on the current server.
> The server will process the URI as if it were a whole new request,
> running the URI translation, MIME type checking, and other phases
> before invoking the appropriate content handler for the new URI.
> The content handler that eventually runs is not necessarily the same
> as the one that invoked internal_redirect().
> This method should only be called within a content handler.

Yes, I understand that. What I am saying is this ...

After a successfull internal_redirect(), and return OK my content handler has
exited - The content has now reached my client. Now my cleanup handler is
executing. I am not understanding why Apache is attempting to write to client
now !!

Also, by using internal_redirect_handler() you can make r->handler (which is the
current handler by default) handle this redirect().

>
> ssn> Why is apache re-doing the request after a internal_redirect() ? ( and
that too
> ssn> in the cleanup phase ??)
>
> ssn> Please help me understand this. Any hints most appreciated :-)
> mailto:cubic@wr.miee.ru

regards
srp

Re: ap_rwrite()/ap_rvputs() called in PerlCleanupHandler

am 16.10.2002 15:59:18 von srp

Hello,

Caught the problem. It was a unexpected 'print STDOUT' happening in the Cleanup
Handler. :-( sorry for the trouble.

regards
srp

You wrote:

> Envelope-to: srp@symonds.net
> Received: from symonds.net [63.194.20.32]
> by symonds.net with smtp (Exim 3.35 #1 (Debian))
> id 181QC0-0001uo-00; Tue, 15 Oct 2002 04:48:56 -0700
> Date: Tue, 15 Oct 2002 04:48:56 -0700 (PDT)
> To: cubic@wr.miee.ru
> Cc: modperl@apache.org, srp@symonds.net
> Subject: Re: ap_rwrite()/ap_rvputs() called in PerlCleanupHandler
> X-URL: http://www.symonds.net/
> Message-Id:
> From: srp@symonds.net
> X-UIDL: HH\"!TZ>!!W[T"!+/6!!
> Status: RO
>
> Thanks for reply ..
>
> > Hello!
> >
> > internal_redirect()
> > The required argument is an absolute URI path on the current server.
> > The server will process the URI as if it were a whole new request,
> > running the URI translation, MIME type checking, and other phases
> > before invoking the appropriate content handler for the new URI.
> > The content handler that eventually runs is not necessarily the same
> > as the one that invoked internal_redirect().
> > This method should only be called within a content handler.
>
> Yes, I understand that. What I am saying is this ...
>
> After a successfull internal_redirect(), and return OK my content handler has
> exited - The content has now reached my client. Now my cleanup handler is
> executing. I am not understanding why Apache is attempting to write to client
> now !!
>
> Also, by using internal_redirect_handler() you can make r->handler (which is
the
> current handler by default) handle this redirect().
>
> >
> > ssn> Why is apache re-doing the request after a internal_redirect() ? ( and
> that too
> > ssn> in the cleanup phase ??)
> >
> > ssn> Please help me understand this. Any hints most appreciated :-)
> > mailto:cubic@wr.miee.ru
>
> regards
> srp
>
>