Fix: Add infinite loop protection to API pagination

This commit is contained in:
kim
2026-01-29 17:32:58 +08:00
parent e64bdbe2fa
commit ac62783fc6
+14 -1
View File
@@ -507,6 +507,7 @@ def fetch_all_packages():
version = "2022-01-01"
all_packages = []
current_token = ""
seen_tokens = set()
while True:
try:
@@ -524,8 +525,20 @@ def fetch_all_packages():
if items:
all_packages.extend(items)
next_token = data.get("Result", {}).get("NextToken", "")
if not next_token or next_token == current_token:
# Infinite Loop Protection
if not next_token:
break
if next_token == current_token:
break
if next_token in seen_tokens:
if DEBUG_MODE:
print(
f"DEBUG: Detected pagination cycle with token {next_token}. Stopping."
)
break
seen_tokens.add(next_token)
current_token = next_token
time.sleep(0.2)
except Exception as e: