You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sander Smeenk <ss...@freshdot.net> on 2003/04/23 16:32:03 UTC

Scripts generating 4069+ bytes of STDERR logs jam Apache 2.0.45

Hi,

I'm using Apache 2.0.45 (mpm-prefork). Recently I discovered that Apache2
doesn't like it very much when a CGI-script that it runs, generates
about 4K of debug data.

The apache2 process will hang in a poll().
The script process will hang in a write(2, "...").

If you wait long enough, apache2 times out the script, kills it, and you
get a 500. If you kill the script process by hand, it blurts out
'Premature end of script headers' followed by a part, but not all, of
the errors it should report and the browser-end is left waiting.

A simple test script would be:

| #!/usr/bin/perl -wT
| 
| use strict;
| use CGI;
| 
| my $CGI = new CGI;
| 
| print STDERR "a" x 4096 . "\n";
| 
| print $CGI->header();
| print "Hello folks!\n";
| exit 0;

This is bound to "hang" like described above. Tested on 3 systems.

It looks like Apache2 has a 4K buffer to store an errormessage and
something goes wrong when there's more than, or about 4K data to handle.

<offtopic>
Is there any way to have Apache2 error.log's in simple format?
I only want the errors, not prefixed with date, time, type and client,
and postfixed with a referrer URL. I couldn't find anything yet.
It's really hard to read script debug information now ;)
</offtopic>

Hope my information helps!

Kind regards,
Sander Smeenk.

-- 
| Thou shalt not weigh more than thy refrigerator
| 1024D/08CEC94D - 34B3 3314 B146 E13C 70C8  9BDB D463 7E41 08CE C94D

Re: Scripts generating 4069+ bytes of STDERR logs jam Apache 2.0.45

Posted by Jeff Trawick <tr...@attglobal.net>.
Sander Smeenk wrote:

> I'm using Apache 2.0.45 (mpm-prefork). Recently I discovered that Apache2
> doesn't like it very much when a CGI-script that it runs, generates
> about 4K of debug data.

yep, known problem

it will also stall if your cgi tries to write more than 4K of output 
(stdout or stderr) before reading all of the request body (e.g., post data)

(replace 4K in my text and yours with your kernel's pipe buffer size)

I have hacked up^H^H^H^H^H^H^H^H^Hheavily revised mod_cgi to handle a 
CGI's stdin/stdout/stderr "properly".  With this change it no longer 
matters in which order your script chooses to do I/O on 
stdin/stdout/stderr.  But

a) it currently buffers the entire reponse for non-nph scripts since I 
haven't yet taught it when to process the script headers
b) other changes are not completely tested
c) no support yet for weenie operating systems like Win32 where APR 
can't poll on pipes
d) because it doesn't alter the filter API or make funny things happen 
in the filter support code, but instead uses normal multi-plexed I/O 
idioms directly in mod_cgi, I'm afraid some people might not like my 
solution

You're free to play with it if you want.

> <offtopic>
> Is there any way to have Apache2 error.log's in simple format?
> I only want the errors, not prefixed with date, time, type and client,
> and postfixed with a referrer URL. I couldn't find anything yet.
> It's really hard to read script debug information now ;)
> </offtopic>

ErrorLog |/path/to/user/provided/reformatter

Reformat it to your heart's desire.