Skip to content

Commit

Permalink
Fix applying reconnect_count
Browse files Browse the repository at this point in the history
reconnect_count is not applied on server disconnect because exception caught before except clause to handle reconnect.
  • Loading branch information
zzeekk authored Sep 3, 2023
1 parent 2bb2f94 commit aff8342
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mqtt_io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from hashlib import sha1
from importlib import import_module
from typing import Any, Dict, List, Optional, Tuple, Type, Union, overload
from asyncio_mqtt.error import MqttCodeError

import backoff # type: ignore
from typing_extensions import Literal
Expand Down Expand Up @@ -1214,19 +1215,16 @@ async def _main_loop(self) -> None:
if self.config["mqtt"].get("ha_discovery", {}).get("enabled"):
self._ha_discovery_announce()

try:
await asyncio.gather(*self.critical_tasks)
except asyncio.CancelledError:
break
except Exception: # pylint: disable=broad-except
_LOG.exception("Exception in critical task:")
await asyncio.gather(*self.critical_tasks)
except asyncio.CancelledError:
break
except MQTTException:
except (MQTTException,MqttCodeError):
if reconnects_remaining is not None:
reconnect = reconnects_remaining > 0
reconnects_remaining -= 1
_LOG.exception("Connection to MQTT broker failed")
except Exception: # pylint: disable=broad-except
_LOG.exception("Exception in critical task:")

finally:
_LOG.debug("Clearing events and cancelling 'critical_tasks'")
Expand Down

0 comments on commit aff8342

Please sign in to comment.