1
0
mirror of https://github.com/home-assistant/operating-system.git synced 2026-04-18 07:56:19 +01:00

Fix retry in hassio container fetching, retry with backoff (#4572)

The retry when fetching containers from the registry didn't work because the
script was executed with `set -e`. Capture the error code also for non-zero
exit status.

Also use while loop instead of recursion and back off exponentially - start
with 5s and multiply by 3 (i.e. 5s, 15s, 45s - waiting in total up to 1 minute
for the registry to recover).
This commit is contained in:
Jan Čermák
2026-03-10 08:12:14 +01:00
committed by GitHub
parent 98dd85971e
commit 123b023f20

View File

@@ -14,21 +14,24 @@ dst_dir=$6
retry() { retry() {
local retries="$1" local retries="$1"
local cmd=$2 local cmd=$2
local delay=5
local output local output
output=$(eval "$cmd") local rc
local rc=$? output=$(eval "$cmd") && rc=$? || rc=$?
# shellcheck disable=SC2086 while [ "$rc" -ne 0 ] && [ "$retries" -gt 0 ]; do
if [ $rc -ne 0 ] && [ $retries -gt 0 ]; then echo "Retrying \"$cmd\" in ${delay}s ($retries retries left)..." >&2
echo "Retrying \"$cmd\" $retries more times..." >&2 sleep "${delay}s"
sleep 3s
# shellcheck disable=SC2004 # shellcheck disable=SC2004
retry $(($retries - 1)) "$cmd" delay=$(($delay * 3))
else # shellcheck disable=SC2004
echo "$output" retries=$(($retries - 1))
return $rc output=$(eval "$cmd") && rc=$? || rc=$?
fi done
echo "$output"
return $rc
} }
image_name=$(jq -e -r --arg image_json_name "${image_json_name}" \ image_name=$(jq -e -r --arg image_json_name "${image_json_name}" \