Commit b904931
fix(session): 消除 end_session 路径上 ~1 秒的 event loop 阻塞 (Project-N-E-K-O#843)
* fix(session): 消除 end_session 路径上 ~1 秒的 event loop 阻塞
Qwen Realtime 的 `ClientConnection.close()` 默认 close_timeout=10s,
若远端迟迟不回 CLOSE 帧,`await self.ws.close()` 会把 end_session
协程挂起数百毫秒到数秒(日志中观察到 ~1s)。
改用 asyncio.wait_for(..., timeout=0.5),超时后 transport.abort()
做本地强制关闭,保证 end_session 快速返回、主事件循环心跳不受影响。
* refactor(session): 改用 close_timeout 参数替代 transport.abort() 私有 API
CodeRabbit 指出 ClientConnection.transport 不是公开稳定接口。改用
websockets.connect(..., close_timeout=0.5):close handshake 超时后
库内部会自行 abort transport,效果等价但只依赖公开 API。
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1e621d2 commit b904931
1 file changed
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
485 | | - | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
486 | 489 | | |
487 | 490 | | |
488 | 491 | | |
| |||
1691 | 1694 | | |
1692 | 1695 | | |
1693 | 1696 | | |
1694 | | - | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
1695 | 1700 | | |
1696 | 1701 | | |
1697 | 1702 | | |
| |||
0 commit comments