fix: subscribe error catch (#1551)

This commit is contained in:
Li Shuzhen
2025-12-16 08:27:30 +08:00
committed by GitHub
parent 30ce1b4970
commit 500ed76971

View File

@@ -519,15 +519,12 @@ class _MipsClient(ABC):
if not self._mqtt or not self._mqtt.is_connected(): if not self._mqtt or not self._mqtt.is_connected():
self.log_error(f'mips sub when not connected, {topic}') self.log_error(f'mips sub when not connected, {topic}')
return return
try:
if topic not in self._mips_sub_pending_map: if topic not in self._mips_sub_pending_map:
self._mips_sub_pending_map[topic] = 0 self._mips_sub_pending_map[topic] = 0
if not self._mips_sub_pending_timer: if not self._mips_sub_pending_timer:
self._mips_sub_pending_timer = self._internal_loop.call_later( self._mips_sub_pending_timer = self._internal_loop.call_later(
0.01, self.__mips_sub_internal_pending_handler, topic) 0.01, self.__mips_sub_internal_pending_handler, topic)
except Exception as err: # pylint: disable=broad-exception-caught
# Catch all exception
self.log_error(f'mips sub internal error, {topic}. {err}')
@final @final
def _mips_unsub_internal(self, topic: str) -> None: def _mips_unsub_internal(self, topic: str) -> None:
@@ -736,11 +733,16 @@ class _MipsClient(ABC):
self.log_error(f'retry mips sub internal error, {topic}') self.log_error(f'retry mips sub internal error, {topic}')
continue continue
subbed_count += 1 subbed_count += 1
result = mid = None
try:
result, mid = self._mqtt.subscribe(topic, qos=self.MIPS_QOS) result, mid = self._mqtt.subscribe(topic, qos=self.MIPS_QOS)
if result == MQTT_ERR_SUCCESS: if result == MQTT_ERR_SUCCESS:
self._mips_sub_pending_map.pop(topic) self._mips_sub_pending_map.pop(topic)
self.log_debug(f'mips sub internal success, {topic}') self.log_debug(f'mips sub internal success, {topic}')
continue continue
except Exception as err: # pylint: disable=broad-exception-caught
# Catch all exception
self.log_error(f'mips sub internal error, {topic}. {err}')
self._mips_sub_pending_map[topic] = count+1 self._mips_sub_pending_map[topic] = count+1
self.log_error( self.log_error(
f'retry mips sub internal, {count}, {topic}, {result}, {mid}') f'retry mips sub internal, {count}, {topic}, {result}, {mid}')