Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

flush error in modperl on system commands

by barsh (Novice)
on Jan 20, 2012 at 22:24 UTC ( #949066=perlquestion: print w/ replies, xml ) Need Help??
barsh has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I have been getting sporadic errors in my modperl2, freebsd linux environment when a system command is executed. When it fails, which is roughly 25% of the time, the user gets a 500 error and there is a error log message of the form

"Fri Jan 20 16:31:44 2012 error client <IP> (null): flush can't be called before the response phase at /usr/local/apache/lib/perl/<module name> <line> <referer>".

From the <module name> and <line> values I can see these always correspond to system commands.

In the perldoc for system I found the below paragraph: "Beginning with v5.6.0, Perl will attempt to flush all files opened for output before any operation that may do a fork, but this may not be supported on some platforms (see perlport). To be safe, you may need to set $| ($AUTOFLUSH in English) or call the autoflush() method of IO::Handle on any open handles."

So I tried adding

local $| = 0;
before every system command but to no avail.

So it appears somehow the modperl http buffer is being flushed when system is called but I can't figure out why or what to do about it.

Any wisdom would be greatly appreciated!

Comment on flush error in modperl on system commands
Download Code
Re: flush error in modperl on system commands
by Anonymous Monk on Jan 21, 2012 at 04:40 UTC

    What does the system call do?

    Redirect stdout and stderr to nul?

    Launch in background with Proc::Background?

    Did you try running apache with strace?

    Are you running a proxy?

      It happens on multiple system calls. One example is running ps2pdf12 to create a pdf from ps file, in that instance I am not capturing stdout or stdin. In other instances where this error occurs I am capture both (running using backticks and redirecting stderr to stdout in the command).

      Have not tried proc::background, or strace, so will try that. Also read Apache::SubProcess might be worth trying so I will also attempt that today. Will report back if anything works.

      Also read last night that including Test::MockObject was creating a similar type of error for somebody: http://www.apache-httpd.com/list/39/962672.html. I was not including that module but did have Test::More, although I tried removing Test::More and it hasn't helped.

      Thanks!

        One more follow up: removing Test::More solved the problem on my production server (I stress tested it with 10000 consecutive queries) but did not solve the error on my dev server (and yes, both servers exhibit the error when Test::More is included). Nothing else on the dev server is using any Test package that I could find. For the time being, since the production server is working this is satisfactory for me so I am no longer actively seeking a solution, although it is still very curious to me.

        I won't call this solved, but for any seekers of perl wisdom with this issue in the future I recommend checking libraries you are including, especially any library from the Test package.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://949066]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-09-18 02:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls