Skip to content

Commit 46d2564

Browse files
committed
fix: add retry to initial installing POST (post_to_api / post_to_api_vm)
The initial 'installing' record MUST exist for all subsequent status updates to succeed. Previously this was fire-and-forget with no retry, so timeouts/503s silently dropped ~50% of installations. Both post_to_api (LXC) and post_to_api_vm now retry up to 3 times with 1s delay between attempts. Also captures HTTP response code to detect failures instead of using curl -f (silent fail).
1 parent 3701737 commit 46d2564

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

misc/api.func

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -687,18 +687,23 @@ EOF
687687
[[ "${DEV_MODE:-}" == "true" ]] && echo "[DEBUG] Sending to: $TELEMETRY_URL" >&2
688688
[[ "${DEV_MODE:-}" == "true" ]] && echo "[DEBUG] Payload: $JSON_PAYLOAD" >&2
689689

690-
# Fire-and-forget: never block, never fail
691-
local http_code
692-
if [[ "${DEV_MODE:-}" == "true" ]]; then
693-
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
694-
-H "Content-Type: application/json" \
695-
-d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || true
696-
echo "[DEBUG] HTTP response code: $http_code" >&2
697-
else
698-
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
699-
-H "Content-Type: application/json" \
700-
-d "$JSON_PAYLOAD" &>/dev/null || true
701-
fi
690+
# Send initial "installing" record with retry.
691+
# This record MUST exist for all subsequent updates to succeed.
692+
local http_code="" attempt
693+
for attempt in 1 2 3; do
694+
if [[ "${DEV_MODE:-}" == "true" ]]; then
695+
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
696+
-H "Content-Type: application/json" \
697+
-d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || http_code="000"
698+
echo "[DEBUG] post_to_api attempt $attempt HTTP=$http_code" >&2
699+
else
700+
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
701+
-H "Content-Type: application/json" \
702+
-d "$JSON_PAYLOAD" -o /dev/null 2>/dev/null) || http_code="000"
703+
fi
704+
[[ "$http_code" =~ ^2[0-9]{2}$ ]] && break
705+
[[ "$attempt" -lt 3 ]] && sleep 1
706+
done
702707

703708
POST_TO_API_DONE=true
704709
}
@@ -789,10 +794,15 @@ post_to_api_vm() {
789794
EOF
790795
)
791796

792-
# Fire-and-forget: never block, never fail
793-
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
794-
-H "Content-Type: application/json" \
795-
-d "$JSON_PAYLOAD" &>/dev/null || true
797+
# Send initial "installing" record with retry (must succeed for updates to work)
798+
local http_code="" attempt
799+
for attempt in 1 2 3; do
800+
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
801+
-H "Content-Type: application/json" \
802+
-d "$JSON_PAYLOAD" -o /dev/null 2>/dev/null) || http_code="000"
803+
[[ "$http_code" =~ ^2[0-9]{2}$ ]] && break
804+
[[ "$attempt" -lt 3 ]] && sleep 1
805+
done
796806

797807
POST_TO_API_DONE=true
798808
}

0 commit comments

Comments
 (0)