From aac69f6a3e4211ba63088deed88810403199643e Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Feb 2026 18:58:06 +0100 Subject: [PATCH] fix: always defer health tests to background on startup Cold start with large pools blocked the server for the entire test duration. Now start() always defers health testing so the server listens immediately. Proxies become available as tests complete. --- src/s5p/pool.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/s5p/pool.py b/src/s5p/pool.py index 4bffa5d..b50dba5 100644 --- a/src/s5p/pool.py +++ b/src/s5p/pool.py @@ -71,23 +71,15 @@ class ProxyPool: async def start(self) -> None: """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. + Always defers health testing to background so the server starts + listening immediately. On warm start, cached alive proxies are + available right away. On cold start, proxies become available + as the background test progresses. """ self._load_state() - warm = bool(self._alive_keys) await self._fetch_all_sources() - - 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() - self._save_state() + self._save_state() + self._tasks.append(asyncio.create_task(self._deferred_full_test())) self._tasks.append(asyncio.create_task(self._refresh_loop())) self._tasks.append(asyncio.create_task(self._health_loop()))