mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 13:34:13 +03:00
fix MQTT disconnect reason code comparison bug
The mypy fixes introduced a bug where disconnect callback was comparing reason_code == 0 instead of reason_value == 0. Since reason_code is a ReasonCode object, it never equals integer 0, causing clean disconnects to never be detected and infinite retry loops to occur. Fixed by using reason_value (extracted from reason_code.value) for numeric comparison, consistent with how we extract the value for logging. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b0f189056a
commit
f68ff53bd9
@ -24,7 +24,6 @@ class MqttClient(Communicator):
|
|||||||
self._reconnect_thread: Optional[threading.Thread] = None
|
self._reconnect_thread: Optional[threading.Thread] = None
|
||||||
self._reconnect_delay = 10 # Retry every 10 seconds
|
self._reconnect_delay = 10 # Retry every 10 seconds
|
||||||
self._stop_reconnect: bool = False
|
self._stop_reconnect: bool = False
|
||||||
self._cleanup_in_progress: bool = False
|
|
||||||
|
|
||||||
def subscribe(self, receiver: Callable[[str, str], None]) -> None:
|
def subscribe(self, receiver: Callable[[str, str], None]) -> None:
|
||||||
"""Wrapper for allowing dispatcher to subscribe."""
|
"""Wrapper for allowing dispatcher to subscribe."""
|
||||||
@ -240,16 +239,12 @@ class MqttClient(Communicator):
|
|||||||
f"MQTT disconnected - reason: '{reason_name}', code: {reason_value}, type: {type(reason_code)}"
|
f"MQTT disconnected - reason: '{reason_name}', code: {reason_value}, type: {type(reason_code)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Don't attempt reconnection if we're stopping, cleaning up, or if it was a clean disconnect
|
# Don't attempt reconnection if we're stopping or if it was a clean disconnect
|
||||||
if self._stop_reconnect:
|
if self._stop_reconnect:
|
||||||
logger.error("MQTT not reconnecting - stop flag set")
|
logger.error("MQTT not reconnecting - stop flag set")
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._cleanup_in_progress:
|
if reason_value == 0:
|
||||||
logger.error("MQTT not reconnecting - cleanup in progress")
|
|
||||||
return
|
|
||||||
|
|
||||||
if reason_code == 0:
|
|
||||||
logger.error("MQTT not reconnecting - clean disconnect (code 0)")
|
logger.error("MQTT not reconnecting - clean disconnect (code 0)")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -384,12 +379,9 @@ class MqttClient(Communicator):
|
|||||||
# Clean up old client if it exists
|
# Clean up old client if it exists
|
||||||
if self.client is not None:
|
if self.client is not None:
|
||||||
try:
|
try:
|
||||||
self._cleanup_in_progress = True
|
|
||||||
self.client.disconnect()
|
self.client.disconnect()
|
||||||
self.client.loop_stop()
|
self.client.loop_stop()
|
||||||
self._cleanup_in_progress = False
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._cleanup_in_progress = False
|
|
||||||
pass # Ignore cleanup errors
|
pass # Ignore cleanup errors
|
||||||
|
|
||||||
# Create completely fresh client and attempt connection
|
# Create completely fresh client and attempt connection
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user