Fix: Add infinite loop protection to API pagination
This commit is contained in:
+14
-1
@@ -507,6 +507,7 @@ def fetch_all_packages():
|
|||||||
version = "2022-01-01"
|
version = "2022-01-01"
|
||||||
all_packages = []
|
all_packages = []
|
||||||
current_token = ""
|
current_token = ""
|
||||||
|
seen_tokens = set()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -524,8 +525,20 @@ def fetch_all_packages():
|
|||||||
if items:
|
if items:
|
||||||
all_packages.extend(items)
|
all_packages.extend(items)
|
||||||
next_token = data.get("Result", {}).get("NextToken", "")
|
next_token = data.get("Result", {}).get("NextToken", "")
|
||||||
if not next_token or next_token == current_token:
|
|
||||||
|
# Infinite Loop Protection
|
||||||
|
if not next_token:
|
||||||
break
|
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
|
current_token = next_token
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user