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.
This commit is contained in:
user
2026-02-17 18:58:06 +01:00
parent 6d9a21ac02
commit aac69f6a3e
+6 -14
View File
@@ -71,23 +71,15 @@ class ProxyPool:
async def start(self) -> None: async def start(self) -> None:
"""Load state, fetch sources, start background loops. """Load state, fetch sources, start background loops.
On warm start (state file has alive proxies), the pool begins Always defers health testing to background so the server starts
serving immediately using cached state and defers all health listening immediately. On warm start, cached alive proxies are
testing to background tasks. On cold start, a full health available right away. On cold start, proxies become available
test runs before returning so the caller has live proxies. as the background test progresses.
""" """
self._load_state() self._load_state()
warm = bool(self._alive_keys)
await self._fetch_all_sources() await self._fetch_all_sources()
self._save_state()
if warm: self._tasks.append(asyncio.create_task(self._deferred_full_test()))
# 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._tasks.append(asyncio.create_task(self._refresh_loop())) self._tasks.append(asyncio.create_task(self._refresh_loop()))
self._tasks.append(asyncio.create_task(self._health_loop())) self._tasks.append(asyncio.create_task(self._health_loop()))