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