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()