refactor: add configurable DNS/curl timeouts and retries, detect service proxy, and improve connection checks

This commit is contained in:
Andrey Petelin
2025-11-25 17:04:31 +05:00
parent 68c61aed50
commit d52f6e26ae

View File

@@ -473,42 +473,55 @@ remove_cron_job() {
list_update() { list_update() {
echolog "🔄 Starting lists update..." echolog "🔄 Starting lists update..."
local nslookup_timeout=3
local nslookup_attempts=10
local curl_timeout=5
local curl_attempts=10
local curl_max_timeout=10
local delay=3
local i local i
for i in $(seq 1 60); do # DNS Check
if nslookup -timeout=1 openwrt.org > /dev/null 2>&1; then for i in $(seq 1 $nslookup_timeout); do
if nslookup -timeout=$nslookup_timeout openwrt.org > /dev/null 2>&1; then
echolog "✅ DNS check passed" echolog "✅ DNS check passed"
break break
fi fi
log "DNS is unavailable [$i/60]" echolog "DNS is unavailable [$i/$nslookup_attempts]"
sleep 3 sleep $delay
done done
if [ "$i" -eq 60 ]; then if [ "$i" -eq $nslookup_attempts ]; then
echolog "❌ DNS check failed after 60 attempts" echolog "❌ DNS check failed after $nslookup_attempts attempts"
return 1 return 1
fi fi
for i in $(seq 1 60); do # Github Check
config_get_bool download_lists_via_proxy "settings" "download_lists_via_proxy" "0" for i in $(seq 1 $curl_attempts); do
if [ "$download_lists_via_proxy" -eq 1 ]; then local service_proxy_address
if http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" curl -s -m 3 https://github.com > /dev/null; then service_proxy_address="$(get_service_proxy_address)"
if [ -n "$http_proxy_address" ]; then
if curl -s -x "http://$service_proxy_address" -m $curl_timeout https://github.com > /dev/null; then
echolog "✅ GitHub connection check passed (via proxy)" echolog "✅ GitHub connection check passed (via proxy)"
break break
fi fi
else else
if curl -s -m 3 https://github.com > /dev/null; then if curl -s -m $curl_timeout https://github.com > /dev/null; then
echolog "✅ GitHub connection check passed" echolog "✅ GitHub connection check passed"
break break
fi fi
fi fi
echolog "GitHub is unavailable [$i/60]" echolog "GitHub is unavailable [$i/$curl_attempts] (max-timeout=$curl_timeout)"
sleep 3 if [ "$curl_timeout" -lt $curl_max_timeout ]; then
curl_timeout=$((curl_timeout + 1))
fi
sleep $delay
done done
if [ "$i" -eq 60 ]; then if [ "$i" -eq $curl_attempts ]; then
echolog "❌ GitHub connection check failed after 60 attempts" echolog "❌ GitHub connection check failed after $curl_attempts attempts"
return 1 return 1
fi fi