@@ -122,6 +122,7 @@ def __init__(self, config: conf.ConfigType):
122122 self ._nib = NIB ()
123123 self ._network_key = None
124124 self ._concurrent_requests_semaphore = None
125+ self ._currently_waiting_requests = 0
125126 self ._route_discovery_futures = {}
126127 self ._join_announce_tasks = {}
127128
@@ -978,25 +979,31 @@ async def _limit_concurrency(self):
978979 """
979980 Async context manager that prevents devices from being overwhelmed by requests.
980981 Mainly a thin wrapper around `asyncio.Semaphore` that logs when it has to wait.
981-
982- TODO: it would be better to also delay requests in response to `TABLE_FULL`.
983982 """
984983
985984 start_time = time .time ()
986985 was_locked = self ._concurrent_requests_semaphore .locked ()
987986
988987 if was_locked :
989- LOGGER .debug ("Max concurrency reached, delaying requests" )
988+ self ._currently_waiting_requests += 1
989+ LOGGER .debug (
990+ "Max concurrency reached, delaying requests (%s enqueued)" ,
991+ self ._currently_waiting_requests ,
992+ )
990993
991- async with self ._concurrent_requests_semaphore :
992- if was_locked :
993- LOGGER .debug (
994- "Previously delayed request is now running, "
995- "delayed by %0.2f seconds" ,
996- time .time () - start_time ,
997- )
994+ try :
995+ async with self ._concurrent_requests_semaphore :
996+ if was_locked :
997+ LOGGER .debug (
998+ "Previously delayed request is now running, "
999+ "delayed by %0.2f seconds" ,
1000+ time .time () - start_time ,
1001+ )
9981002
999- yield
1003+ yield
1004+ finally :
1005+ if was_locked :
1006+ self ._currently_waiting_requests -= 1
10001007
10011008 def _receive_zdo_message (
10021009 self ,
0 commit comments