Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix applying mqtt.reconnect_count by reordering except clauses #331

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 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 # type: ignore

import backoff # type: ignore
from typing_extensions import Literal
Expand Down Expand Up @@ -1394,21 +1395,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:")
_LOG.error("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")
_LOG.error("Connection to MQTT broker failed")
_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
Loading