kyle has asked for the wisdom of the Perl Monks concerning the following question:

My fellow monks,

I'm hoping someone else has run across this before because it looks pretty odd to me.

I have a request that, when run appears to produce the page it's supposed to, but at the end of the page source, there's this:

</html>HTTP/1.1 200 OK Date: Thu, 18 Sep 2008 17:05:29 GMT Server: Apache/1.3.34 (Ubuntu) mod_perl/1.29 Keep-Alive: timeout=8, max=99 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>200 OK</TITLE> </HEAD><BODY> <H1>OK</H1> The server encountered an internal error or misconfiguration and was unable to complete your request. <!-- ...more stuff... -->

There is nothing in the error logs.

I've narrowed it down to here in the application:

# process template page my $t = $self->template; $t->process( $template, $template_vars, $output ) or die sprintf q{Template error in '%s': %s}, $template, $t->err +or(); return OK; }

If I stick a print in right before the return, it appears between the end of the valid page and the beginning of the "OK error message".

My guess is that something is going haywire during object destruction somewhere, but I haven't thought of a way to debug this. If any monk has some insight, I'd really appreciate it.

Update: As it turns out this was caused by that little problem with Error in which someone tries to return from within one of its blocks and winds up returning to just outside the block instead—because the block is secretly an anonymous sub. Execution would fall off the end of the enclosing sub without ever hitting a return, and most of the time it just so happened that the last value evaluated (and therefore returned) would be the same as the value returned by OK() (specifically, zero).

Replies are listed 'Best First'.
Re: Request returns "200 OK", reports internal server error.
by perrin (Chancellor) on Sep 18, 2008 at 18:06 UTC
    It just means you had already sent the header when the error occurred. My guess about the nature of the error is that you didn't import Apache2::Const::OK and that "OK" is just a string. That's not what apache wants to see.

      Thanks for your comment! The code in question has in it:

      use Apache::Constants qw( OK REDIRECT etc. );

      Also, this is only triggered in a special case. That is, something like this:

      sub general_request_handler { # do the usual stuff if ( $r->param( 'special' ) ) { # go off and do something special } # etc. }

      We're taking the same path otherwise, and the "return OK" is fine there, so I don't think that's the problem here. Also, it doesn't happen every time the special case is used, only for certain users, certain data sets.

      Thanks again.

        Well, the word "OK" in your error response is very suspicious. Try adding a warn to log the value of OK, and try making that sub return "OK()" to force the call to the imported sub.
Re: Request returns "200 OK", reports internal server error.
by pjotrik (Friar) on Sep 18, 2008 at 19:42 UTC
    Looks like you're using Template::Toolkit... try experimenting with the third parameter to $t->process, e.g. setting it to STDERR - that way you should see what's the result of your template processing and see the server response without any intervening content.

    I second the suggestion by perrin, that the "OK" may be source of the problems, I recall having a weird code where use Apache::Constants qw( OK REDIRECT etc. ); worked on one computer and thrown 500 on another, maybe you could try changing it to Apache::Constants::OK()