fix: defer health tests on warm start for instant startup

On warm start, trust persisted alive state and serve immediately.
Health tests run in background. Cold start behavior unchanged.

Previously warm start blocked on testing all cached-alive proxies
before binding the listen port, causing multi-minute delays when
the chain or proxies were slow to respond.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-15 22:01:18 +01:00
parent 5418b30441
commit 590126bcf8

View File

@@ -66,21 +66,21 @@ class ProxyPool:
# -- public interface ----------------------------------------------------
async def start(self) -> None:
"""Load state, fetch sources, run initial health test, start loops."""
"""Load state, fetch sources, start background loops.
On warm start (state file has alive proxies), the pool begins
serving immediately using cached state and defers all health
testing to background tasks. On cold start, a full health
test runs before returning so the caller has live proxies.
"""
self._load_state()
warm_keys = list(self._alive_keys)
warm = bool(self._alive_keys)
await self._fetch_all_sources()
if warm_keys:
# warm start: quick-test previously-alive proxies first
valid_keys = [k for k in warm_keys if k in self._proxies]
if valid_keys:
await self._run_health_tests(keys=valid_keys)
if warm:
# trust persisted alive state, verify in background
self._save_state()
self._tasks.append(asyncio.create_task(self._deferred_full_test()))
else:
await self._run_health_tests()
self._save_state()
else:
# cold start: test everything before serving
await self._run_health_tests()