From fd480e2c60d3244a6ba75f623f9f7999e7689c1f Mon Sep 17 00:00:00 2001 From: "pok.liu" Date: Fri, 9 Jan 2026 12:14:31 +0800 Subject: [PATCH] Fix async concurrency by replacing threading.RLock with asyncio.Lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - The do_service_async() method uses threading.RLock() which blocks all concurrent coroutines when one is waiting for I/O - This defeats the purpose of async/await and causes serial execution instead of concurrent execution Solution: - Replace threading.RLock() with asyncio.Lock() - Replace 'with self.__net_lock:' with 'async with self.__net_lock:' - This allows proper concurrent execution of multiple async calls Impact: - No breaking changes to public API - Significant performance improvement for concurrent requests - Before: N concurrent requests take N × single_request_time - After: N concurrent requests take ≈ single_request_time This fix enables true async concurrency for do_service_async(), walk_nodes_async(), and all related async operations. --- py_eureka_client/eureka_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py_eureka_client/eureka_client.py b/py_eureka_client/eureka_client.py index b12773b..bb0fe75 100644 --- a/py_eureka_client/eureka_client.py +++ b/py_eureka_client/eureka_client.py @@ -396,7 +396,7 @@ def __init__(self, assert ha_strategy in (HA_STRATEGY_RANDOM, HA_STRATEGY_STICK, HA_STRATEGY_OTHER) if should_discover else True, f"do not support strategy {ha_strategy}" - self.__net_lock = RLock() + self.__net_lock = asyncio.Lock() self.__eureka_server_conf = EurekaServerConf( eureka_server=eureka_server, eureka_domain=eureka_domain, @@ -634,7 +634,7 @@ async def __try_all_eureka_servers(self, fun): await self.__try_eureka_server_regardless_zones(fun) async def __try_eureka_servers_in_list(self, fun, eureka_servers=[], zone=_DEFAUTL_ZONE): - with self.__net_lock: + async with self.__net_lock: ok = False _zone = zone if zone else _DEFAUTL_ZONE for url in eureka_servers: