From 123b023f207437fa6294690be6bab168a3ae14fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Tue, 10 Mar 2026 08:12:14 +0100 Subject: [PATCH] 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). --- .../package/hassio/fetch-container-image.sh | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/buildroot-external/package/hassio/fetch-container-image.sh b/buildroot-external/package/hassio/fetch-container-image.sh index 35d6873fa..25230cf96 100755 --- a/buildroot-external/package/hassio/fetch-container-image.sh +++ b/buildroot-external/package/hassio/fetch-container-image.sh @@ -14,21 +14,24 @@ dst_dir=$6 retry() { local retries="$1" local cmd=$2 + local delay=5 local output - output=$(eval "$cmd") - local rc=$? + local rc + output=$(eval "$cmd") && rc=$? || rc=$? - # shellcheck disable=SC2086 - if [ $rc -ne 0 ] && [ $retries -gt 0 ]; then - echo "Retrying \"$cmd\" $retries more times..." >&2 - sleep 3s + while [ "$rc" -ne 0 ] && [ "$retries" -gt 0 ]; do + echo "Retrying \"$cmd\" in ${delay}s ($retries retries left)..." >&2 + sleep "${delay}s" # shellcheck disable=SC2004 - retry $(($retries - 1)) "$cmd" - else - echo "$output" - return $rc - fi + delay=$(($delay * 3)) + # shellcheck disable=SC2004 + retries=$(($retries - 1)) + output=$(eval "$cmd") && rc=$? || rc=$? + done + + echo "$output" + return $rc } image_name=$(jq -e -r --arg image_json_name "${image_json_name}" \