mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-10-27 16:10:49 +08:00
fix: drop non-UTF-8 cloud mips message instead of crashing mqtt loop (#1750)
MipsCloudClient._on_mips_message decodes the push payload with a bare
payload.decode('utf-8'). Some cloud pushes carry payloads that are not
valid UTF-8, which raises UnicodeDecodeError inside paho's on_message,
aborts the read loop and silently drops the message. Lost device
online/offline pushes can leave a device stuck unavailable until the
config entry is reloaded manually.
Catch UnicodeDecodeError, log the topic and the payload hex for
diagnosis, and skip the message so that one malformed push cannot
break message processing.
Related to #1749
This commit is contained in:
@@ -1102,7 +1102,16 @@ class MipsCloudClient(_MipsClient):
|
||||
if not bc_list:
|
||||
return
|
||||
# The message from the cloud is not packed.
|
||||
payload_str: str = payload.decode('utf-8')
|
||||
try:
|
||||
payload_str: str = payload.decode('utf-8')
|
||||
except UnicodeDecodeError as err:
|
||||
# Some cloud pushes carry a payload that is not valid UTF-8.
|
||||
# Drop the message instead of raising, otherwise the exception
|
||||
# aborts paho's read loop and subsequent messages may be lost.
|
||||
self.log_error(
|
||||
f'on message, drop non-utf-8 payload, {err}, {topic}, '
|
||||
f'{payload.hex()}')
|
||||
return
|
||||
# self.log_debug(f"on broadcast, {topic}, {payload}")
|
||||
for item in bc_list or []:
|
||||
if item.handler is None:
|
||||
|
||||
Reference in New Issue
Block a user