From 4901eb851756f3e752303f62a8f1f9d5ffd27e83 Mon Sep 17 00:00:00 2001 From: reform Date: Sat, 14 Nov 2026 01:50:04 +0200 Subject: [PATCH] shim: 5xx no longer parks keys (upstream flap drained the pool to 2/41); health_loop rotates keys per model --- shim.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shim.py b/shim.py index 21fc1a8..bbab86f 100644 --- a/shim.py +++ b/shim.py @@ -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)