From 590126bcf87331a383e4aa8600b81fd22f3b4da3 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 15 Feb 2026 22:01:18 +0100 Subject: [PATCH] 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 --- src/s5p/pool.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/s5p/pool.py b/src/s5p/pool.py index cca803d..0d099fb 100644 --- a/src/s5p/pool.py +++ b/src/s5p/pool.py @@ -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) - self._save_state() - self._tasks.append(asyncio.create_task(self._deferred_full_test())) - else: - await self._run_health_tests() - self._save_state() + if warm: + # trust persisted alive state, verify in background + self._save_state() + self._tasks.append(asyncio.create_task(self._deferred_full_test())) else: # cold start: test everything before serving await self._run_health_tests()