Skip Menu |

This queue is for tickets about the IPC-Run3 CPAN distribution.

Report information
The Basics
Id: 52317
Status: open
Priority: 0/
Queue: IPC-Run3

People
Owner: Nobody in particular
Requestors: RSCHUPP [...] cpan.org
Cc: PLICEASE [...] cpan.org
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.043
Fixed in: (no value)



Subject: Calling run3 garbles STDIN
If run3 is called while reading from STDIN, some input will be lost. Basically any scenario while (<STDIN>) { ... run3 [ ... ], \undef, \$out, \$err; ... } causes some records to be lost or mutilated. To demonstrate run the attached test file.
Subject: stdin.t
#!perl -w use Test::More; use IPC::Run3; use File::Temp qw(tempfile); use strict; ## test whether reading from STDIN is affected when ## run3 is called in between # create a test file for input containing 1000 lines my $nlines = 1000; my @exp_lines; my ($fh, $file) = tempfile(UNLINK => 1); for (my $i = 1; $i <= $nlines; $i++) { my $line = "this is line $i"; push @exp_lines, $line; print $fh $line, "\n"; } close $fh; # call run3 at different lines (any problem might manifest itself # on different lines, probably due to different buffering of input) my @try = (5, 10, 50, 100, 200, 500); plan tests => @try * 2; my ( $in, $out, $err ); foreach my $t (@try) { my $nread = 0; my $unexpected; open STDIN, "<", $file or die "can't open file $file: $!"; while (<STDIN>) { chomp; $unexpected = qq[line $nread: expected "$exp_lines[$nread]", got "$_"\n] unless $exp_lines[$nread] eq $_ || $unexpected; $nread++; if ($nread == $t) { run3 [ $^X, '-e', 'print q[something]' ], \undef, \$out, \$err; die "command failed" unless $? == 0; } } close STDIN; is($nread, $nlines, "STDIN was read completely"); ok(!$unexpected, "STDIN as expected") or diag($unexpected); }
Looks like this caused by the way STDIN is redirected by run3. Instead of something like: open SAVED_STDIN, "<&STDIN"; # save STDIN open STDIN, "<&=".fileno($filehandle_of_tempfile_for_in); ... system ...; ... open STDIN, "<&SAVED_STDIN"; # restore STDIN it uses POSIX::dup() on the underlying platform file descriptors. The above is how redirection is handled for STDOUT and STDERR and the code is still in Run3.pm, but has been commented out for ages: # The open() call here seems to not force fd 0 in some cases; # I ran in to trouble when using this in VCP, not sure why. # the dup2() seems to work. Resurrecting the above code fixes the problem on the few platforms (Linux, Windows) I can test it on and causes no regressions.
Sorry, what's the status of this bug? Patch applied? Needs to be? Pull requests would be great. -- rjbs
On 2013-09-25 21:31:42, RJBS wrote: Show quoted text
> Sorry, what's the status of this bug?
Bug is still present (IPC::Run3 0.046, e.g. tested with Perl 5.18.1 on Linux). Show quoted text
> Patch applied? Needs to be? Pull requests would be great.
I'll try to come up with a pull request over the weekend. Cheers, Roderich
From: ppisar [...] redhat.com
Dne Čt 26.zář.2013 14:54:17, RSCHUPP napsal(a): Show quoted text
> On 2013-09-25 21:31:42, RJBS wrote:
> > Sorry, what's the status of this bug?
> > Bug is still present (IPC::Run3 0.046, e.g. tested with Perl 5.18.1 on > Linux). >
> > Patch applied? Needs to be? Pull requests would be great.
> > I'll try to come up with a pull request over the weekend. > > Cheers, Roderich
This patch seems to be <https://github.com/rschupp/IPC-Run3/commit/8ebe48760cfdc78fbf4fc46413dde9470121b99e>. Is there any progress? I've just hit into this problem and I could not believe such a bug has not yet been fixed. -- Petr
RT-Send-CC: ppisar [...] redhat.com, rjbs [...] cpan.org
On 2014-02-06 06:47:34, ppisar wrote: Show quoted text
> This patch seems to be <https://github.com/rschupp/IPC- > Run3/commit/8ebe48760cfdc78fbf4fc46413dde9470121b99e>.
Correct. Cheers, Roerich
My patch doesn't work. On some platforms (e.g. OSX) it fails immediately, on others it fails if you try harder. STDIN can't be reliably saved and restored by any means. Cheers, Roderich
On Wed May 27 11:44:37 2015, RSCHUPP wrote: Show quoted text
> My patch doesn't work. On some platforms (e.g. OSX) it fails immediately, > on others it fails if you try harder. > > STDIN can't be reliably saved and restored by any means. > > Cheers, Roderich
Perhaps the correct resolution is to then document the limitation, such as this: https://github.com/rjbs/IPC-Run3/pull/10