Skip to content

fix: 修复 WebSocket 反向连接断开后无法正确重连的问题 - #113

Open
This-is-XiaoDeng wants to merge 1 commit into
masterfrom
fix/ws-reserve-connection
Open

fix: 修复 WebSocket 反向连接断开后无法正确重连的问题#113
This-is-XiaoDeng wants to merge 1 commit into
masterfrom
fix/ws-reserve-connection

Conversation

@This-is-XiaoDeng

Copy link
Copy Markdown
Member

问题描述

OneBot 11 的 ws-reserve 在因为各种原因断开连接时,WebSocket 连接会失去原子性,导致:

  1. EventClient.push_event() 方法没有处理 ConnectionClosedError 异常
  2. 当 WebSocket 因 keepalive ping 超时断开后,任务异常未被捕获("Task exception was never retrieved")
  3. 重连时没有关闭旧连接,下游 NoneBot2 会显示已有连接而拒绝新的连接

修复方案

  1. EventClient.push_event() 中添加 ConnectionClosedError 异常处理
  2. reconnect() 中先关闭旧连接再建立新连接,避免下游服务器保留旧连接拒绝新连接
  3. 修复了 WebSocket 因 keepalive ping 超时断开后任务异常未被捕获的问题

修改文件

  • network/v11/ws_reverse.py

测试

  • 已在本地验证代码修改正确
  • 建议在实际环境中测试 WebSocket 断开重连功能

- 在 EventClient.push_event() 中添加 ConnectionClosedError 异常处理
- 在 reconnect() 中先关闭旧连接再建立新连接,避免下游服务器保留旧连接拒绝新连接
- 修复了 WebSocket 因 keepalive ping 超时断开后任务异常未被捕获的问题
@github-actions
github-actions Bot requested a review from montmorill August 16, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant