Revert "优化微信同步超时兜底并下沉头像缓存预热"

This reverts commit c3830d905e.
This commit is contained in:
Liu
2026-05-01 12:45:28 +08:00
parent f9e5a6f5bf
commit 994f452b99
5 changed files with 80 additions and 171 deletions

View File

@@ -18,7 +18,6 @@ import aiofiles
from utils.video_utils import get_first_frame, get_first_frame_bytes
from utils.trace_context import format_trace_prefix
from wechat_ipad import UserLoggedOut
from wechat_ipad.errors import RequestTimeoutError
from wechat_ipad.client.base import WechatAPIClientBase
@@ -732,41 +731,15 @@ class MessageMixin(WechatAPIClientBase):
Raises:
UserLoggedOut: 未登录时调用
RequestTimeoutError: 同步接口超时时抛出,方便上层做重试而不是直接退出主循环
根据error_handler处理错误
"""
if not self.wxid:
raise UserLoggedOut("请先登录")
# `/api/Msg/Sync` 在没有新消息时,服务端经常会把请求挂住一段时间再返回,
# 行为更接近“短轮询/长轮询”而不是普通的即时 RPC。
# 因此这里不能继续沿用 10 秒总超时,否则在空闲期也会被误判成异常。
timeout = aiohttp.ClientTimeout(
total=70,
connect=10,
sock_connect=10,
sock_read=60,
)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session:
json_param = {"Wxid": self.wxid, "Scene": 0, "Synckey": ""}
try:
response = await session.post(f'http://{self.ip}:{self.port}/api/Msg/Sync', json=json_param)
# 某些服务端实现不会稳定返回 `application/json`
# 这里放宽 content-type 校验,避免把“已收到响应”误判成解析失败。
json_resp = await response.json(content_type=None)
except asyncio.TimeoutError as exc:
self.logging.warning(
"同步消息超时: wxid:{} server={}:{} connect_timeout={}s read_timeout={}s total_timeout={}s",
self.wxid,
self.ip,
self.port,
timeout.sock_connect,
timeout.sock_read,
timeout.total,
)
raise RequestTimeoutError(
f"SyncMessage 接口调用超时,读超时={timeout.sock_read}s总超时={timeout.total}s"
) from exc
response = await session.post(f'http://{self.ip}:{self.port}/api/Msg/Sync', json=json_param)
json_resp = await response.json()
if json_resp.get("Success"):
return json_resp.get("Data")

View File

@@ -33,8 +33,3 @@ class UserLoggedOut(Exception):
class BanProtection(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class RequestTimeoutError(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)