Fix race in tmpfile
Some checks failed
Deploy DNS Configuration / deploy (push) Has been cancelled

This commit is contained in:
Kirill Kodanev 2025-09-15 20:54:04 +03:00
parent a206ec509d
commit 8b1cef6944

View file

@ -84,25 +84,28 @@ query_api() {
dbg " -> API attempt #$attempt for $domain" dbg " -> API attempt #$attempt for $domain"
tmpfile=$(mktemp) tmpfile=$(mktemp)
TEMP_FILES+=("$tmpfile") curl -sS --compressed \
http_code=$(curl -sS --compressed \
-m 10 --connect-timeout 5 \ -m 10 --connect-timeout 5 \
--retry 2 --retry-connrefused \ --retry 2 --retry-connrefused \
-H 'Accept: application/json' \ -H 'Accept: application/json' \
-w '%{http_code}' \ -w '%{http_code}' \
-o "$tmpfile" \ -o "$tmpfile" \
"${API_URL}${domain}" 2>>"$DEBUG_LOG" || true) "${API_URL}${domain}" 2>>"$DEBUG_LOG" || true
http_code=$(tail -n1 "$tmpfile")
body=$(cat "$tmpfile") body=$(cat "$tmpfile")
preview="$(printf '%s' "$body" | tr '\n' ' ' | cut -c1-400)" preview="$(printf '%s' "$body" | tr '\n' ' ' | cut -c1-400)"
dbg " -> HTTP=$http_code, preview=${preview}" dbg " -> HTTP=$http_code, preview=${preview}"
if [ "$http_code" = "200" ] && jq -e . "$tmpfile" >/dev/null 2>&1; then if [ "$http_code" = "200" ] && jq -e . "$tmpfile" >/dev/null 2>&1; then
echo "$tmpfile" # возвращаем путь к tmp json файлу cat "$tmpfile" # вернём тело JSON напрямую
rm -f "$tmpfile"
return 0 return 0
fi fi
rm -f "$tmpfile"
if [ "$attempt" -ge "$max_attempts" ]; then if [ "$attempt" -ge "$max_attempts" ]; then
ERRORS["$domain"]="http_${http_code}_or_invalid_json" ERRORS["$domain"]="http_${http_code}_or_invalid_json"
dbg " -> Failed after $attempt attempts, preview=${preview}" dbg " -> Failed after $attempt attempts, preview=${preview}"
@ -116,6 +119,7 @@ query_api() {
done done
} }
if [ ! -f "$INPUT_FILE" ]; then if [ ! -f "$INPUT_FILE" ]; then
err "Input file not found: $INPUT_FILE" err "Input file not found: $INPUT_FILE"
exit 3 exit 3