-
Notifications
You must be signed in to change notification settings - Fork 210
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
Prevent git from hanging a process #6140
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
use Carp; | ||
use Cwd 'abs_path'; | ||
use Filesys::Df qw(df); | ||
use IPC::Run(); | ||
use IPC::Run qw(run timeout); | ||
use Mojo::URL; | ||
use Regexp::Common 'URI'; | ||
use Time::Seconds; | ||
|
@@ -333,13 +333,17 @@ | |
sub run_cmd_with_log_return_error ($cmd, %args) { | ||
my $stdout_level = $args{stdout} // 'debug'; | ||
my $stderr_level = $args{stderr} // 'debug'; | ||
my $timeout_duration = 30; | ||
log_info('Running cmd: ' . join(' ', @$cmd)); | ||
my ($stdin, $stdout_err, $stdout, $stderr) = ('') x 4; | ||
try { | ||
my ($stdin, $stdout_err, $stdout, $stderr) = ('') x 4; | ||
my $ipc_run_succeeded = IPC::Run::run($cmd, \$stdin, \$stdout, \$stderr); | ||
my $ipc_run = run($cmd, \$stdin, \$stdout, \$stderr, timeout($timeout_duration)); | ||
my $return_code = $?; | ||
chomp $stderr; | ||
if ($ipc_run_succeeded) { | ||
#my $return_code = $?; | ||
# use Data::Dumper; | ||
#print "***";print Dumper($@); | ||
if ($ipc_run) { | ||
OpenQA::Log->can("log_$stdout_level")->($stdout); | ||
OpenQA::Log->can("log_$stderr_level")->($stderr); | ||
log_info("cmd returned $return_code"); | ||
|
@@ -349,20 +353,30 @@ | |
log_error("cmd returned $return_code"); | ||
} | ||
return { | ||
status => $ipc_run_succeeded, | ||
status => $ipc_run, | ||
return_code => $return_code, | ||
stdout => $stdout, | ||
stderr => $stderr, | ||
}; | ||
} | ||
catch { | ||
return { | ||
status => 0, | ||
return_code => undef, | ||
stderr => 'an internal error occurred', | ||
stdout => '', | ||
my $additional_info = "If you use http for CASEDIR or NEEDLES_DIR is adviced to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, we shouldn't add lengthy directions into the error message, but link to the documentation, as it was suggested in the ticket |
||
configure git with the insteadof option in the .gitconfig file. | ||
Run the following command to: | ||
git config [--global] url.\"git://github.com\".insteadOf https://github.com"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
my $stderr_msg = ($_ =~ /timeout/) | ||
? join(' ', @$cmd) . " timed out after $timeout_duration seconds \nNote:\n$additional_info" | ||
: 'an internal error occurred'; | ||
#$stderr_msg .= "prompt detected" if $stdout =~ /Username.*:/; | ||
log_error($stderr_msg); | ||
return { | ||
status => 0, | ||
return_code => undef, | ||
stderr => $stderr_msg, | ||
stdout => '', | ||
}; | ||
}; | ||
}; | ||
|
||
} | ||
|
||
sub asset_type_from_setting { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you not use
GIT_ASKPASS
andGIT_TERMINAL_PROMPT
like suggested in the ticket?Waiting for a timing out command seems way more complicated than just telling git to not prompt in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that with the
timeout
we gonna have a general solution when the _run_cmd (or more specifically run_cmd_with_log_return_error) encounter similar issue.GIT_ASKPASS and GIT_TERMINAL_PROMPT make the logic more complicated IMO but also provide a better error as I didnt find a way to catch the prompt in the $stdout somehow.
Maybe both can be applied at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's complicated about using two env vars. It's as simple as it gets?