shim: 5xx no longer parks keys (upstream flap drained the pool to 2/41); health_loop rotates keys per model

This commit is contained in:
2026-11-14 01:50:04 +02:00
parent e8486ad186
commit 4901eb8517
+7 -4
View File
@@ -124,12 +124,14 @@ def health_loop(interval=120):
while True:
try:
ks = alive()
k = ks[int(time.time() // 600) % len(ks)] if ks else None
if k:
if ks:
from concurrent.futures import ThreadPoolExecutor
pairs = [(a, b) for a, b in BASE_SLUG.items() if FALLBACK.get(a)]
base_i = int(time.time() // 120)
with ThreadPoolExecutor(max_workers=4) as ex:
oks = list(ex.map(lambda ab: _slug_ok(ab[1], k, timeout=70), pairs))
oks = list(ex.map(
lambda t: _slug_ok(t[1][1], ks[(base_i + t[0]) % len(ks)], timeout=70),
enumerate(pairs)))
for (alias, base), ok in zip(pairs, oks):
want = base if ok else FALLBACK[alias]
if MAP.get(alias) != want:
@@ -229,7 +231,8 @@ class H(BaseHTTPRequestHandler):
last = (code, err)
continue
if code in (500, 502, 503, 504):
mark_dead(k, 15) # upstream flap: не вина ключа, пауза минимальная
# upstream flap: НЕ паркуем ключ (иначе флап апстрима парализует весь пул),
# просто идём следующим ключом
last = (code, err)
continue
return self._relay(code, err)