From 3a5df3544bcd021c96f2066ffaf6cefcc5836d75 Mon Sep 17 00:00:00 2001 From: Maxim Pogozhiy Date: Sat, 18 Jan 2025 22:40:49 +0700 Subject: [PATCH] Route53 Exponential backoff --- dnsapi/dns_aws.sh | 50 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/dnsapi/dns_aws.sh b/dnsapi/dns_aws.sh index c88c9d9ca5..e8d1463556 100755 --- a/dnsapi/dns_aws.sh +++ b/dnsapi/dns_aws.sh @@ -323,7 +323,6 @@ aws_rest() { _debug2 CredentialScope "$CredentialScope" StringToSign="$Algorithm\n$RequestDate\n$CredentialScope\n$HashedCanonicalRequest" - _debug2 StringToSign "$StringToSign" kSecret="AWS4$AWS_SECRET_ACCESS_KEY" @@ -361,20 +360,45 @@ aws_rest() { url="$AWS_URL/$ep?$qsr" fi - if [ "$mtd" = "GET" ]; then - response="$(_get "$url")" - else - response="$(_post "$data" "$url")" - fi + # Exponential backoff + max_retries=10 + attempt=1 + base_sleep=5 - _ret="$?" - _debug2 response "$response" - if [ "$_ret" = "0" ]; then - if _contains "$response" "(Throttling|RequestThrottled|RateLimit)|Rate exceeded"; then + _err "AWS throttling encountered, attempt $attempt" + attempt=$(_math "$attempt" + 1) + if [ "$attempt" -le "$max_retries" ]; then + sleep_time=$(_math "$base_sleep" "*" 2 "^" "$((attempt - 1))") + _err "Sleeping $sleep_time seconds before retry..." + _sleep "$sleep_time" + continue + else + _err "Max retries ($max_retries) reached. Giving up." + return 1 + fi + else + return 1 + fi + fi + else + return "$_ret" + fi + break + done return "$_ret" }