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:
+6
-14
@@ -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()))
|
||||
|
||||
Reference in New Issue
Block a user