From 60dd5aeffb5f45324ca1ed06be7563f650432ac4 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Thu, 16 Apr 2026 16:34:56 +1000 Subject: [PATCH] routermon: break chunk loop early when circuit breaker fires Stop sending further API requests mid-batch once the backoff is triggered, saving remaining missing IPs as empty placeholders immediately instead of waiting for them to timeout one-by-one. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- routermon/receiver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routermon/receiver.py b/routermon/receiver.py index 060791a..3ffef31 100644 --- a/routermon/receiver.py +++ b/routermon/receiver.py @@ -423,6 +423,16 @@ def _geo_worker_loop(): _geo_consecutive_misses, _GEO_BACKOFF_SECS, ) _geo_consecutive_misses = 0 + # Save remaining uncached IPs and stop the loop early. + remaining = missing[i + 100:] + if remaining: + IPGeoCache.objects.bulk_create( + [IPGeoCache(ip=ip) for ip in remaining + if ip not in geo_cache], + ignore_conflicts=True, + ) + _geo_skip.update(remaining) + break elif results: _geo_consecutive_misses = 0