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