-
Notifications
You must be signed in to change notification settings - Fork 578
[PATCH] Reap child in case where exception has been thrown #12371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From [email protected]This is a bug report for perl from philip.boulain@smoothwall.net, IPC::Open3 does not behave as documented for exec failures in the As documented, open3 should return the child PID, which should In practice, open3 throws an exception, as for other errors (I There are therefore two problems: Attached: The test case failed correctly without the fix, and passes with Flags: Site configuration information for perl 5.14.2: Configured by Debian Project at Fri Aug 10 21:43:06 UTC 2012. Summary of my perl5 (revision 5 version 14 subversion 2) configuration: Platform: Locally applied patches: @INC for perl 5.14.2: Environment for perl 5.14.2: -- Smoothwall Ltd Smoothwall Limited is registered in England, Company Number: 4298247 |
From [email protected]0001-Reap-child-in-case-where-exception-has-been-thrown.patchFrom 7be72bf92786362968ed95b3a040288b2f6a5e0d Mon Sep 17 00:00:00 2001
From: Philip Boulain <[email protected]>
Date: Mon, 3 Sep 2012 15:16:26 +0100
Subject: [PATCH] Reap child in case where exception has been thrown
If open3 throws due to an issue such as an exec failure, the caller
cannot know the child PID to wait for. Therefore it is our
responsibility to reap it.
Also update POD, since on some platforms exec failures now ARE raised as
exceptions (since perlbug #72016).
---
ext/IPC-Open3/lib/IPC/Open3.pm | 4 +++-
ext/IPC-Open3/t/IPC-Open3.t | 7 ++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index 31c68af..8a2264e 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -57,7 +57,8 @@ as file descriptors.
open3() returns the process ID of the child process. It doesn't return on
failure: it just raises an exception matching C</^open3:/>. However,
C<exec> failures in the child (such as no such file or permission denied),
-are just reported to CHLD_ERR, as it is not possible to trap them.
+are just reported to CHLD_ERR under Windows and OS/2, as it is not possible
+to trap them.
If the child process dies for any reason, the next write to CHLD_IN is
likely to generate a SIGPIPE in the parent, which is fatal by default.
@@ -295,6 +296,7 @@ sub _open3 {
if ($bytes_read) {
(my $bang, $to_read) = unpack('II', $buf);
read($stat_r, my $err = '', $to_read);
+ waitpid $kidpid, 0; # Reap child which should have exited
if ($err) {
utf8::decode $err if $] >= 5.008;
} else {
diff --git a/ext/IPC-Open3/t/IPC-Open3.t b/ext/IPC-Open3/t/IPC-Open3.t
index 7b85b82..6ab519d 100644
--- a/ext/IPC-Open3/t/IPC-Open3.t
+++ b/ext/IPC-Open3/t/IPC-Open3.t
@@ -14,10 +14,11 @@ BEGIN {
}
use strict;
-use Test::More tests => 37;
+use Test::More tests => 38;
use IO::Handle;
use IPC::Open3;
+use POSIX ":sys_wait_h";
my $perl = $^X;
@@ -154,6 +155,10 @@ $TB->current_test($test);
isnt($@, '',
'open3 of a non existent program fails with an exception in the parent')
or do {waitpid $pid, 0};
+ SKIP: {
+ skip 'open3 returned, our responsibility to reap', 1 unless $@;
+ is(waitpid(-1, WNOHANG), -1, 'failed exec child is reaped');
+ }
}
$pid = eval { open3 'WRITE', '', 'ERROR', '/non/existent/program'; };
--
1.7.9.5
|
From @jkeenanOn Mon Sep 03 08:42:06 2012, philip.boulain@smoothwall.net wrote:
Your demonstration program, open3bug, uses 'pstree', which appears to be Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From [email protected]On 6 September 2012 02:35, James E Keenan via RT
Hmm, sorry, I don't see how to get comparable behaviour from BSD If you have access to GNU ps (BSD has no --ppid-alike I can find), you sub show_pstree { system ('ps', 'ufp', Failing that, here's the output on my machine (configuration as per ==== USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND open3 threw an exception! After IPC, before waitpid (if known): USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND No child PID known; can't waitpid. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
From @tonycozOn Wed Sep 05 18:35:49 2012, jkeenan wrote:
A simpler way to demonstrate it, in one terminal: # cwd is a built blead in another: pallas:~ tony$ ps w (the processes with the Z+ flags are zombies) The patch fixes the problem. I'll apply this in a couple of days unless someone points out a problem Tony |
From @tonycozOn Wed Jul 24 23:07:35 2013, tonyc wrote:
Thanks, applied as cccbbce. Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
From @ikegamiOn Thu, Jul 25, 2013 at 2:07 AM, Tony Cook via RT <perlbug-followup@perl.org
It changes my code and it looks right to me. |
Migrated from rt.perl.org#114722 (status was 'resolved')
Searchable as RT114722$
The text was updated successfully, but these errors were encountered: