From 2b1b21fb2f1c4c58589821a05cc47c42a24ab04a Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Sun, 10 Dec 2023 18:02:20 -0500 Subject: [PATCH] Limit request concurrency --- zigpy_xbee/zigbee/application.py | 43 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/zigpy_xbee/zigbee/application.py b/zigpy_xbee/zigbee/application.py index 2158b95..d5971c3 100644 --- a/zigpy_xbee/zigbee/application.py +++ b/zigpy_xbee/zigbee/application.py @@ -302,29 +302,30 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None: "Cannot send a packet to a device without a known IEEE address" ) - send_req = self._api.tx_explicit( - long_addr, - short_addr, - packet.src_ep or 0, - packet.dst_ep or 0, - packet.cluster_id, - packet.profile_id, - packet.radius, - tx_opts, - packet.data.serialize(), - ) - - try: - v = await asyncio.wait_for(send_req, timeout=TIMEOUT_TX_STATUS) - except asyncio.TimeoutError: - raise zigpy.exceptions.DeliveryError( - "Timeout waiting for ACK", status=TXStatus.NETWORK_ACK_FAILURE + async with self._limit_concurrency(): + send_req = self._api.tx_explicit( + long_addr, + short_addr, + packet.src_ep or 0, + packet.dst_ep or 0, + packet.cluster_id, + packet.profile_id, + packet.radius, + tx_opts, + packet.data.serialize(), ) - if v != TXStatus.SUCCESS: - raise zigpy.exceptions.DeliveryError( - f"Failed to deliver packet: {v!r}", status=v - ) + try: + v = await asyncio.wait_for(send_req, timeout=TIMEOUT_TX_STATUS) + except asyncio.TimeoutError: + raise zigpy.exceptions.DeliveryError( + "Timeout waiting for ACK", status=TXStatus.NETWORK_ACK_FAILURE + ) + + if v != TXStatus.SUCCESS: + raise zigpy.exceptions.DeliveryError( + f"Failed to deliver packet: {v!r}", status=v + ) @zigpy.util.retryable_request() def remote_at_command(