mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
fix(performance-tester): cancel receiver task on all exit paths
Ensure the message receiver is cancelled and awaited in a finally block, so a server-side close does not leave an orphan task or an unretrieved exception.
This commit is contained in:
parent
d3c669d1f9
commit
7f477e3b29
1 changed files with 52 additions and 46 deletions
|
|
@ -171,6 +171,7 @@ async def run(args) -> int:
|
|||
log("msg", type=t, raw=json.dumps(msg, ensure_ascii=False)[:160])
|
||||
|
||||
rx_task = asyncio.create_task(rx())
|
||||
try:
|
||||
await ws.send(
|
||||
json.dumps(
|
||||
{
|
||||
|
|
@ -223,7 +224,12 @@ async def run(args) -> int:
|
|||
if state["tts"] and state["tts"][-1] == "stop":
|
||||
break
|
||||
await asyncio.sleep(0.25)
|
||||
finally:
|
||||
rx_task.cancel()
|
||||
try:
|
||||
await rx_task
|
||||
except BaseException:
|
||||
pass
|
||||
except websockets.exceptions.InvalidStatus as e:
|
||||
print(f"[device-sim] 握手失败:{e}(检查 url / 反向代理)")
|
||||
return 2
|
||||
|
|
|
|||
Loading…
Reference in a new issue