dbooth has asked for the wisdom of the Perl Monks concerning the following question:
Update 3-Jan-2012: SOLVED! I discovered that this problem was being caused by the mere inclusion of the following module:
even though no functions from that module were being called. Since this appears to be a bug in Test::MockObject, I reported the bug here: https://rt.cpan.org/Public/Bug/Display.html?id=73723 That bug report shows the exact minimal handler code that I used to reproduce the bug.use Test::MockObject;
Original post:
What is the right way to run a shell command from mod_perl2? In a non-mod_perl2 script I would normally use backticks `...` or system(...) but they are causing a child process segmentation fault after several successful HTTP requests, so I am guessing there is some kind of bad interaction with Apache2 threads going on, or some kind of race condition with the child process.
To be clear, from a mod_perl2 response handler I simply wish to run a short shell command and capture its stdout and stderr to files or strings for further processing before sending back the HTTP response. I.e., my response handler should block until the shell command completes. As a simple example I tried both $foo=`date` and system("date > /tmp/date") and they both work correctly for a few HTTP requests and then cause an Apache2 child segmentation fault: "[Mon Jan 02 11:16:46 2012] [notice] child pid 6833 exit signal Segmentation fault (11)". I have verified that it is the Apache2 child process that is seg faulting -- not the "date" process -- by using "pgrep apache2" to list the Apache2 process IDs before running the test, and it is indeed one of those Apache2 PIDs that I see in the Apache2 error log message when this happens.
Update 3-Jan-2012: My current test script successfully makes four HTTP GET requests to my mod_perl2 handler without incident, during which my subprocess command runs properly. On the fifth request, the Apache2 child process tries unsuccessfully to run my subprocess command, and that Apache2 child dies with a segmentation fault, causing the client to receive no data. The failure may not be noticed if you are not carefully watching the Apache2 error log, because Firefox and wget -- though not curl -- seem to automatically re-try the request, and Apache2 automatically spawns new children as needed if its children die.
I have searched the web and found several approaches that sound like they may be of interest, but I do not know which (if any) is the right approach to take:
I've been struggling with this for many hours, and want to be sure that I end up with the right solution, so that my handler won't fail randomly at some future time when I least expect it. I am using Apache 2.2.14-5ubuntu8.7 with the worker MPM, perl 5.10.1 and libapache2-mod-perl2 2.0.4-6ubuntu1 under Ubuntu 10.04.
Suggestions from the masters, please? How should I approach this seemingly simple task?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Correct way to run a shell command from mod_perl2? (Child process segmentation fault)
by repellent (Priest) on Jan 03, 2012 at 00:49 UTC | |
by dbooth (Novice) on Jan 03, 2012 at 03:03 UTC | |
|
Re: Correct way to run a shell command from mod_perl2? (Child process segmentation fault)
by Anonymous Monk on Jan 02, 2012 at 19:11 UTC | |
by dbooth (Novice) on Jan 02, 2012 at 22:07 UTC |