043ce779e69a458456e551c6a8869135d0713dd9
A hot reload that changes the binding signature (url / role / accessToken / reconnectIntervalMs) drives `await this.close()` then `await this.open()` back-to-back. `WsClientAdapter.close()` is synchronous and `WebSocket.close()` just schedules the close frame, so the OLD socket's `'close'` event fires AFTER the new socket has already been assigned to `this.socket`. The close handler did not check the event's origin, so it would null out `this.socket`, drop `connected`, and schedule an unwanted reconnect against the freshly-opened connection. Against a single-connection backend that kicks duplicates this snowballed into a reconnect storm where the bot and the backend repeatedly kicked each other off; against a permissive backend it still left the new connection in a degraded state (events couldn't be sent until the bogus reconnect rebuilt the socket). Add a one-line identity guard at the top of the close handler — when the event arrives from a socket that is no longer the current one, do nothing. The explicitlyClosed / isEnabled checks are kept as the second line of defence for the normal (current-socket) close path. Add three regression tests under tests/ws-client-stale-close.test.ts that mock `@snowluma/websocket` (same approach as adapter-reload-state-machine. test.ts, which avoids the native addon dependency): the reload race scenario from the issue, a real-current-socket close that MUST still drive reconnect, and a close() race against an in-flight close event.
Next Remote Protocol Framework.
Releases · Issues · QQ 群 · Telegram
SnowLuma 是一个基于 TypeScript 的协议转换框架,旨在为 QQ 客户端提供 OneBot v11 标准接口,支持 WebSocket/HTTP 适配、多账号并行及 WebUI 管理。
特性
- OneBot v11 兼容:支持文本、音视频、Markdown、JSON 等消息格式。
- 高性能架构:TypeScript 全栈,基于 pnpm monorepo 管理,核心逻辑分离。
- 现代化管理:内置 WebUI 面板,支持实时日志、密码热更、多账号管理。
- 多适配器支持:WebSocket (Server/Client)、HTTP (Server/Post)。
- 数据持久化:使用 SQLite 存储好友、群组等关系数据。
快速开始
- 从 Releases 下载最新发布包并解压。
- 运行
./launcher.bat(Windows) 或./launcher.sh(Linux)。 - 访问
http://localhost:5099(初始账号admin,密码见控制台输出)。
鸣谢
参考了 LagrangeV2 的协议定义与 NapCatQQ 的实现思路。
Languages
TypeScript
98.9%
CSS
0.5%
JavaScript
0.5%