Skip to content
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

Use IPC::Run3::run3 rather than IPC::Open3::open3 #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ my %WriteMakefileArgs = (
"File::Temp" => 0,
"File::chdir" => 0,
"IPC::Cmd" => 0,
"IPC::Open3" => 0,
"IPC::Run3" => 0,
"Scalar::Util" => 0,
"Sort::Versions" => 0,
"Symbol" => 0,
Expand Down Expand Up @@ -65,7 +65,7 @@ my %FallbackPrereqs = (
"File::chdir" => 0,
"IO::File" => 0,
"IPC::Cmd" => 0,
"IPC::Open3" => 0,
"IPC::Run3" => 0,
"POSIX" => 0,
"Scalar::Util" => 0,
"Sort::Versions" => 0,
Expand Down
36 changes: 11 additions & 25 deletions lib/Git/Wrapper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ delete $ENV{GIT_PAGER_IN_USE};

use File::chdir;
use File::Temp;
use IPC::Open3 qw();
use IPC::Run3 ();
use Scalar::Util qw(blessed);
use Sort::Versions;
use Symbol;
Expand Down Expand Up @@ -87,41 +87,27 @@ sub RUN {
my( $parts , $stdin ) = _parse_args( $cmd , @_ );

my @cmd = ( $self->git , @$parts );

my( @out , @err );

{
local $CWD = $self->dir unless $cmd eq 'clone';

my ($wtr, $rdr, $err);

local *TEMP;
if ($^O eq 'MSWin32' && defined $stdin) {
my $file = File::Temp->new;
$file->autoflush(1);
$file->print($stdin);
$file->seek(0,0);
open TEMP, '<&=', $file;
$wtr = '<&TEMP';
undef $stdin;
}

$err = Symbol::gensym;

print STDERR join(' ',@cmd),"\n" if $DEBUG;

my ($stdout, $stderr);
# Prevent commands from running interactively
local $ENV{GIT_EDITOR} = ' ';
IPC::Run3::run3(\@cmd, \$stdin, \$stdout, \$stderr);

my $pid = IPC::Open3::open3($wtr, $rdr, $err, @cmd);
print $wtr $stdin
if defined $stdin;

close $wtr;
chomp(@out = <$rdr>);
chomp(@err = <$err>);
@out = map {
chomp;
$_;
} split(/\n/, $stdout);

waitpid $pid, 0;
@err = map {
chomp;
$_;
} split(/\n/, $stderr);
};

print "status: $?\n" if $DEBUG;
Expand Down
26 changes: 26 additions & 0 deletions t/deadlock.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use strict;
use warnings;
use Test::More;
use Git::Wrapper;

my $git = Git::Wrapper->new(".", git_binary => "./t/deadlock_helper.sh");

sub _timeout (&) {
my ($code) = @_;

my $timeout = 0;
eval {
local $SIG{ALRM} = sub { $timeout = 1; die "TIMEOUT\n" };
# 5 seconds should be more than enough time to fail properly
alarm 5;
$code->();
alarm 0;
};

return $timeout;
}

my $timeout = _timeout { $git->RUN("test", -STDIN => "test1\ntest2\n") };
is $timeout, 0, "didn't deadlock";

done_testing();
39 changes: 39 additions & 0 deletions t/deadlock_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

# This script is to help assist the deadlock test.
# Write a large amount of text to stdout/stderr and read from stdin and
# then repeat.

line="All work and no play makes Jack a dull boy"

i=1
while test $i -le 1024; do
echo 1-STDOUT$i $line
i=$((i+1))
done

i=1
while test $i -le 1024; do
echo 1-STDERR$i $line
i=$((i+1))
done >&2

echo -n "Reading input: "
read empty

i=1
while test $i -le 1024; do
echo 2-STDOUT$i $line
i=$((i+1))
done

i=1
while test $i -le 1024; do
echo 2-STDERR$i $line
i=$((i+1))
done >&2

echo -n "Reading input: "
read empty

exit 0