Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket方式下增加自动重连功能 #27

Closed
Dewdrops opened this issue Mar 5, 2020 · 4 comments
Closed

Websocket方式下增加自动重连功能 #27

Dewdrops opened this issue Mar 5, 2020 · 4 comments
Labels
domain: core feature 新特性 has solution 已存在解决办法
Milestone

Comments

@Dewdrops
Copy link

Dewdrops commented Mar 5, 2020

Is your feature request related to a problem? Please describe.
选择Websocket连接方式时,如果与Cqhttp服务器的ws连接断掉,就无法收到消息,必须重启应用。

Describe the solution you'd like
当ws连接断开时,能够有可配置(重试次数,重试策略,Exponential Backoff 之类)的自动重连能力。

@shigma shigma added this to the 1.11 milestone Mar 10, 2020
@shigma
Copy link
Member

shigma commented Mar 12, 2020

@Dewdrops 我发布了 1.11.0 版本,增加了 retryTimesretryInterval 两个配置项,当 WebSocket 无法连接或异常中断时将每隔一段时间进行重试。你看这样能满足你的需求吗?

@shigma shigma added the has solution 已存在解决办法 label Mar 12, 2020
@Dewdrops
Copy link
Author

Dewdrops commented Mar 12, 2020

@shigma 非常感谢!

我升级到了1.11.0版本,设置

    retryTimes: 3,
    retryInterval: 15000,

但是似乎没有起作用。

重现方法:

  1. 用 docker 启动 cqhttp 镜像,websocket 连接方式启动 koishi app,此时正常连接并且能收到消息。
  2. stop cqhttp镜像,此时无法收到消息。
  3. 10s后重启镜像,等待数分钟仍然无法收到消息
  4. 重启 koishi app,恢复正常

过程中没有日志输出,是需要配置日志级别吗?

@shigma
Copy link
Member

shigma commented Mar 13, 2020

image

上面是我这里实测的画面。一开始未启动 CQHTTP,当 Koishi App 运行后再启动,可以看到 Koishi 进行了多次尝试。之后将 CQHTTP 重载,可以看到 Koishi 再次尝试重连成功。

如果你使用的是 koishi 的命令行工具,可以配置 logLevel 为 3。如果你直接进行调用,可以首先设定环境变量 DEBUG=koishi:*。这两种方法都能够看到上面的提示。

@Dewdrops
Copy link
Author

感谢耐心解答。

我使用的环境变量加载方法是dotenv,之前应该是调用顺序没注意,DEBUG环境变量没正确设置。
重新测试之后功能一切正常,并且能够看到期望的日志输出。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: core feature 新特性 has solution 已存在解决办法
Projects
None yet
Development

No branches or pull requests

2 participants