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

Bug: 使用 HTTP 服务 (@koishijs/plugin-http) 的 ctx.http.ws 时, 远端拒绝后会导致 Koishi 崩溃自动重载 #1430

Open
lovemilk2333 opened this issue Jul 18, 2024 · 1 comment
Labels
bug BUG next 下个大版本实装 upstream bug 上游依赖库的问题

Comments

@lovemilk2333
Copy link

Describe the bug

使用 HTTP 服务 (@koishijs/plugin-http) 的 ctx.http.ws 时, 远端拒绝会造成 APP 出现错误 Error: connect ECONNREFUSED 0.0.0.0:443, 即使不在插件的 apply 函数内运行仍会发生, 后 Koishi 崩溃自动重载, 且对该代码行使用 try-catch 无法捕获拒绝连接的异常 (我 await 了也不行).

Steps to reproduce

依赖 HTTP 服务后, 在任意位置执行如下 ts (确保 ctx 为插件的 Context)

ctx.http.ws('wss://0.0.0.0')

Expected behavior

异常可被 try-catch 捕获处理, 即使未被处理也不应使 Koishi 崩溃, 而应使插件报错停止流程

Screenshots

image

Versions

  • OS: Windows 11 23H2 22631.3810
  • Platform: Any
  • Node version: v18.20.2
  • Koishi version: 4.17.9

Additional context

No response

@lovemilk2333 lovemilk2333 added the bug BUG label Jul 18, 2024
@shigma shigma added the upstream bug 上游依赖库的问题 label Jul 18, 2024
@shigma
Copy link
Member

shigma commented Jul 18, 2024

此问题由 ws 这个库和 node 底层的实现导致。

目前的解决方案是确保任何创建出的 WebSocket 实例都有 onerror。

当 node 最低版本变为 22 以上版本时,将会替换底层实现以解决此问题。

@shigma shigma added the next 下个大版本实装 label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug BUG next 下个大版本实装 upstream bug 上游依赖库的问题
Projects
None yet
Development

No branches or pull requests

2 participants