Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
make sure all relevant futures are re-created before connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmeli committed Dec 16, 2021
1 parent cd407e2 commit 1d65758
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pyduke_energy/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ async def _reconnect(self):
if not res:
_LOGGER.warning("Unsubscribe error: %s", mqtt.error_string(res))
await self._disconnected
self._disconnected = self._loop.create_future() # re-create the future

# Update mqtt_auth and header info
client_id = self._mqtt_auth["clientid"]
Expand All @@ -358,6 +357,12 @@ async def _reconnect(self):

async def _async_mqtt_client_connect(self):
"""Run connect() in an async safe manner to avoid blocking."""
# Re-create the futures
if self._disconnected.done():
self._disconnected = self._loop.create_future()
if self._connected.done():
self._connected = self._loop.create_future()

# Run connect() within an executor thread, since it blocks on socket
# connection for up to `keepalive` seconds: https://git.io/Jt5Yc
try:
Expand Down

0 comments on commit 1d65758

Please sign in to comment.