Skip to content

fix(qbittorrent): handle non-200 response during login to prevent long startup waits#2248

Open
airium wants to merge 1 commit intoOpenListTeam:mainfrom
airium:main
Open

fix(qbittorrent): handle non-200 response during login to prevent long startup waits#2248
airium wants to merge 1 commit intoOpenListTeam:mainfrom
airium:main

Conversation

@airium
Copy link

@airium airium commented Mar 23, 2026

Description / 描述

openlist 默认在启动时访问 8080 端口测试 qbittorrent webui 连通性.
但是如果特殊程序如 vmess websocket 占用 8080, 由于该代理协议的特点, 不会返回任何payload
openlist 尝试登录后会收到 HTTP 101 升级 ws 后会长时间阻塞等待 body, 导致 openlist 在启动半途卡住

❯ ./openlist server
INFO[2026-03-23 15:12:05] reading config file: /opt/openlist/data/config.json
INFO[2026-03-23 15:12:05] load config from env with prefix: OPENLIST_
INFO[2026-03-23 15:12:05] max buffer limit: 95MB
INFO[2026-03-23 15:12:05] mmap threshold: 4MB
INFO[2026-03-23 15:12:05] init logrus...

会卡在这里完全不动, 有时数分钟无法等到:

start HTTP server @ 0.0.0.0:5244

可以使用 curl 快速复现卡住:

❯ curl -v --header 'Referer: http://localhost:8080' --data 'username=admin&password=adminadmin' http://localhost:8080/api/v2/auth/login
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> POST /api/v2/auth/login HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.5.0
> Accept: */*
> Referer: http://localhost:8080
> Content-Length: 34
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 101 Switching Protocols
< Connection: upgrade
< Sec-Websocket-Accept: dGhlIHNhbXBsZSBub25jZQ==
< Upgrade: websocket
< Date: Mon, 23 Mar 2026 07:16:03 GMT
<

根据 qb 官方 api 文档 https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#login, 正常登录仅会返回 HTTP 200
因此可以将非 200 的返回值全部直接视为失败, 从而避免阻塞/卡住

Motivation and Context / 背景

No related

How Has This Been Tested? / 测试

添加该patch后, 启动时qb检测环节遇到非200返回能够正常改出, 不再卡住

WARN [2026-03-23 03:34:32] /home/xxxxxx/src/OpenListTeam/OpenList/internal/bootstrap/offline_download.go:12 github.com/OpenListTeam/OpenList/v4/internal/bootstrap.InitOfflineDownloadTools() init offline download tool qBittorrent failed: failed to login into qBittorrent webui with status code: 101 Switching Protocols

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • [] I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

Copilot AI review requested due to automatic review settings March 23, 2026 07:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the qBittorrent WebUI login flow to fail fast on non-200 HTTP responses, preventing OpenList from blocking during startup when the target endpoint responds with unexpected protocol upgrades (e.g., HTTP 101).

Changes:

  • Add an early StatusCode == 200 check in qBittorrent login to avoid reading a potentially non-terminating response body.
  • Improve startup behavior by returning a clear login failure error when qBittorrent API expectations are not met.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants