From d355e7e6a99d0a283f95db23c3a2d7b50634e1f4 Mon Sep 17 00:00:00 2001 From: Robert Rapp Date: Mon, 19 Jan 2026 19:52:28 +0100 Subject: [PATCH] fix: handle MaxMind 429 and backoff --- .env.example | 3 +++ asn-updater/entrypoint.sh | 12 ++++++++---- asn-updater/update.py | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index ef8e838..6d7b3da 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,6 @@ PDB_INFO_TYPE=Educational/Research # minimum ASN entries for healthy /healthz MIN_ASN_COUNT=10 + +# retry interval after a failed update (e.g., MaxMind 429) +RETRY_SECONDS=3600 diff --git a/asn-updater/entrypoint.sh b/asn-updater/entrypoint.sh index c4594bf..3b76b4c 100644 --- a/asn-updater/entrypoint.sh +++ b/asn-updater/entrypoint.sh @@ -2,12 +2,16 @@ set -eu INTERVAL_SECONDS="${INTERVAL_SECONDS:-2592000}" +RETRY_SECONDS="${RETRY_SECONDS:-3600}" echo "[start] updater interval=${INTERVAL_SECONDS}s out_dir=${OUT_DIR:-/data}" while true; do echo "[run] update now" - python /app/update.py - echo "[sleep] ${INTERVAL_SECONDS}s" - sleep "${INTERVAL_SECONDS}" + if python /app/update.py; then + echo "[sleep] ${INTERVAL_SECONDS}s" + sleep "${INTERVAL_SECONDS}" + else + echo "[warn] update failed; retry in ${RETRY_SECONDS}s" + sleep "${RETRY_SECONDS}" + fi done - diff --git a/asn-updater/update.py b/asn-updater/update.py index 6a4ed4f..3915419 100644 --- a/asn-updater/update.py +++ b/asn-updater/update.py @@ -29,6 +29,12 @@ def download_maxmind_mmdb() -> None: with tempfile.TemporaryDirectory() as td: tgz = os.path.join(td, "GeoLite2-ASN.tar.gz") r = requests.get(url, timeout=TIMEOUT) + if r.status_code == 429: + existing = os.path.join(OUT_DIR, "GeoLite2-ASN.mmdb") + if os.path.exists(existing): + print("[warn] MaxMind rate limited (429); keeping existing mmdb") + return + raise RuntimeError("MaxMind rate limited (429) and no existing mmdb") r.raise_for_status() with open(tgz, "wb") as f: f.write(r.content)