Skip to content

Commit

Permalink
fix: don't exit with fping host is unreachable
Browse files Browse the repository at this point in the history
As ping can return unknown exit codes for unknown cases,
just never bail out to avoid taking bad decisions,
as we retry each second maximum, there's no DoS risk
  • Loading branch information
speed47 committed Dec 5, 2023
1 parent 25ee7dc commit 345a1f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 4 additions & 8 deletions bin/plugin/open/alive
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,18 @@ if (not $host) {

osh_info "Waiting for $host to be alive...";
my $startedat = Time::HiRes::gettimeofday();
my $isFping = 1;
my $firstLoop = 1;
my @command = qw{ fping -- };
push @command, $host;
while (1) {
$fnret = OVH::Bastion::execute(cmd => \@command, noisy_stdout => 1, noisy_stderr => 1);
if ($fnret->err eq 'ERR_EXEC_FAILED') {
if ($isFping) {

if ($firstLoop) {
# maybe fping doesn't work, fallback to ping
@command = qw{ ping -c 1 -w 1 -- };
push @command, $host;
$isFping = 0;
next;
$firstLoop = 0;
next; # restart the loop to exec ping
}
osh_exit $fnret; # we tried both ping and fping :(
}
Expand All @@ -73,9 +72,6 @@ while (1) {
osh_info "Alive after waiting for $delay seconds, exiting!";
osh_ok {waited_for => $delay + 0};
}
elsif (($isFping && $fnret->value->{'sysret'} >= 3) || ($fnret->value->{'sysret'} > 0)) {
osh_exit 'ERR_INTERNAL', "Fatal error returned by (f)ping, aborting";
}
sleep 1;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/functional/launch_tests_on_instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,10 @@ sshclientconfigchg()

dump_vars_and_funcs()
{
set | grep -v -E '^(testno|section|code_warn_exclude|COPROC_PID|LINES|COLUMNS|PIPESTATUS|_|BASH_LINENO|basename|case|json|name|tmpscript|grepit|got|isbad|nbfailedgrep)='
set | grep -v -E '^('\
'testno|section|code_warn_exclude|COPROC_PID|LINES|COLUMNS|PIPESTATUS|_|'\
'BASH_LINENO|basename|case|json|name|tmpscript|grepit|got|isbad|'\
'nbfailedgrep|shouldbe)='
}

runtests()
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/tests.d/360-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ EOS

success alive_withoutHost $a0 --osh alive 127.0.0.1
json .command alive .error_code OK .value.waited_for 0

run alive_unreachable $a0f --osh alive 192.0.2.0
retvalshouldbe 124
}

testsuite_plugins
Expand Down

0 comments on commit 345a1f9

Please sign in to comment.