將qBittorrent容器從 5.1.4 升級至 5.2.0 後啟動無法正常啟動並在日誌中重複出現以下訊息:

[QBITTORRENT] Starting with forwarded port [54321].
[QBITTORRENT] Delaying start until forwarded port is available.

乍看下好像是通訊埠轉發的問題,如果你和我一樣使用 hotio 的 image,同時也正在使用 VPN 功能,很容易就被誤導以為 hotio 的 base image 與新版本的 qBittorrent 有相容性問題,但其實是程式的單例鎖發生了變化。

問題解析

問題的源頭來自 qBittorrent 在 5.2.0 版本中調整了單例鎖定機制。

在 5.2.0 之前,qBittorrent 使用的是基於本基於 fcntl 的 QtLockedFile ,其 lockfile 是個空白檔案。

而 5.2.0 將單例鎖更換為 Qt 內建的 QLockFile 1, 它會將 PID、hostname 等資訊寫入 lockfile。

舊版本留下來的 lockfile 格式,和新版本預期的格式不同。所以當 5.2.0 啟動時,無法正確解析舊版遺留的 lockfile,進而誤判成目前已有執行中的實例導致啟動失敗。

並且 hotio image 的預設 s6 腳本會因為啟動失敗而自動重啟,最終形成無限循環重啟的狀況。

解決方法

將 qBittorrent 的 config 目錄中的 lockfileipc-socket 兩個檔案刪除即可 2

Footnotes

  1. Replace QtLockedFile with QLockFile by drustill · Pull Request #23757 · qbittorrent/qBittorrent · GitHub

  2. 5.1.4 lockfile presence causes 5.2.0 to abort with Another qBittorrent instance is already running. · Issue #24164 · qbittorrent/qBittorrent