mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Fix race when waiting for MQTT ACK (#39193)
This commit is contained in:
parent
71acb2c665
commit
3df67ff9e1
@ -939,10 +939,9 @@ class MQTT:
|
|||||||
self.hass.add_job(self._mqtt_handle_mid, mid)
|
self.hass.add_job(self._mqtt_handle_mid, mid)
|
||||||
|
|
||||||
async def _mqtt_handle_mid(self, mid) -> None:
|
async def _mqtt_handle_mid(self, mid) -> None:
|
||||||
if mid in self._pending_operations:
|
if mid not in self._pending_operations:
|
||||||
self._pending_operations[mid].set()
|
self._pending_operations[mid] = asyncio.Event()
|
||||||
else:
|
self._pending_operations[mid].set()
|
||||||
_LOGGER.warning("Unknown mid %d", mid)
|
|
||||||
|
|
||||||
def _mqtt_on_disconnect(self, _mqttc, _userdata, result_code: int) -> None:
|
def _mqtt_on_disconnect(self, _mqttc, _userdata, result_code: int) -> None:
|
||||||
"""Disconnected callback."""
|
"""Disconnected callback."""
|
||||||
@ -957,7 +956,8 @@ class MQTT:
|
|||||||
|
|
||||||
async def _wait_for_mid(self, mid):
|
async def _wait_for_mid(self, mid):
|
||||||
"""Wait for ACK from broker."""
|
"""Wait for ACK from broker."""
|
||||||
self._pending_operations[mid] = asyncio.Event()
|
if mid not in self._pending_operations:
|
||||||
|
self._pending_operations[mid] = asyncio.Event()
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self._pending_operations[mid].wait(), TIMEOUT_ACK)
|
await asyncio.wait_for(self._pending_operations[mid].wait(), TIMEOUT_ACK)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user