Closed VEADoc closed 2 years ago
和 grpc 请求频率是否有关系? 刚启动的时候 缓存里的 没有联系人信息。就需要 grpc 请求获取 短时间 请求过多 导致被服务器断连 ? 有没有这种可能的。🥶
我这边能稳定复现。
机器人加入的群聊有 2586 个
filter = RoomQueryFilter(id=room_id)
room = await self.Room.find(filter)
执行上述代码 百分百 得到一个错误 grpclib.exceptions.StreamTerminatedError: Connection lost
所以我觉得是 grpc 服务器那边短时间内接收到大量请求 ,把我连接给关了 😮💨
通过 on_login
事件 先 分批加载一下 通讯录和群聊
控制住并发度 测试过 [ 1000 ,800 ,500] 三个值, 在有限的测试下 初步认为 一次性加载 500 条数据 sleep 2秒最稳定
async def on_login(self, contact: Contact):
await super().on_login(contact)
"""全量加载一下通讯录和群聊"""
"""分批加载防止 Connect Lost"""
step = 500
"""联系人"""
contact_ids = await self.Contact.get_puppet().contact_list()
contacts: List[Contact] = [self.Contact.load(contact_id) for contact_id in contact_ids]
rich.print(f'[dark_orange] Load {contacts.__len__()} Contacts...')
x = 0
while True:
_contacts = [x for x in contacts[x:x+step]]
if not _contacts:
break
await asyncio.gather(*[contact.ready() for contact in _contacts])
rich.print(f'[cyan] {_contacts.__len__()} Contacts Ready!')
x += step
await asyncio.sleep(2)
"""群聊"""
room_ids = await self.Room.get_puppet().room_search()
rooms = [self.Room.load(room_id) for room_id in room_ids]
rich.print(f'[dark_orange] Load {rooms.__len__()} Rooms...')
x = 0
while True:
_rooms = [x for x in rooms[x:x+step]]
if not _rooms:
break
await asyncio.gather(*[room.ready() for room in _rooms])
rich.print(f'[cyan] {_rooms.__len__()} Rooms Ready!')
x += step
await asyncio.sleep(2)
rich.print(f'[green]Load Success!')
You can update wechaty to get new feature which has solved it.
requirements
Describe your problem
脚本启动后能正常接收消息。
在 联系人find_all 加载全量联系人的时候 抛出
grpclib.exceptions.StreamTerminatedError
错误控制台打印的错误信息如下
随后wechaty自动重启 日志摘要如下
再接着就出现了错误
WechatyPuppetError('puppet_stub should not be none', None, None)
调用say 发送消息也会报错