Closed burritothief closed 1 year ago
@jephdo IIRC, your test scripts log in into qBittorrent but never log out (unless qBittorrent-api does it by itself). Am I right?
Ah thanks, I made the modification to explicitly log out and it completely frees the memory. You're correct.
Then my issue is that other clients don't do this either. As an example, you can search through the Radarr & Sonarr repos where they interact with qBittorrent and you can find a reference to /api/v2/auth/login
, but there's no reference to /api/v2/auth/logout
lol. So they are not logging out either which causes excessive memory usage
I guess I would just expect hitting the /api/v2/torrents/info
endpoint to release the memory after the request-response cycle is over, rather than having to wait for the session to be over.
I guess I would just expect hitting the
/api/v2/torrents/info
endpoint to release the memory after the request-response cycle is over, rather than having to wait for the session to be over.
AFAIK, torrents/info
does not store any data between calls. However, sessions themselves take up a certain amount of memory, so if you are constantly creating a new session, then memory consumption will still constantly grow. Of course, sessions have some inactive timeout, after which they are automatically deleted, but at a high rate of creating new sessions, it should be small enough to help. Unfortunately, qBittorrent has no limit on the number of simultaneously open sessions, which could better prevent problems like yours.
I'll close this issue out since the best way to deal with this is to end the session by explicitly logging out
For anyone else, since some 3rd party clients don't implement the logout endpoint, my short term fix was to set the session timeout parameter to a much smaller value (I previously had it at 7 days), and I'm now using IP whitelisting to avoid logging in
qBittorrent & operating system versions
qBittorrent: 4.5.2 Operating system: Debian GNU/Linux 11 (bullseye) [Linux 5.10.0-19-amd64] Qt: 6.5.0 libtorrent-rasterbar: 2.0.8.0
What is the problem?
Problem Querying the qBittorrent Web API, especially if the client has a large number of torrents, permanently increases memory usage of the app. If you have external apps periodically querying the API, it will indefinitely grow memory usage until the app eventually crashes due to out of memory issues. The problem is really pronounced with large amounts of torrents.
Background In my personal situation I have several Docker containers running qBittorrent-nox instances. Each container has a few thousand torrents. I also have external apps like Radarr and Sonarr connected to my qBittorrent containers. My qBittorrent containers gradually grow in memory usage and typically crash due to OOM errors after 48 hours (on a 2GB RAM virtual machine). I initially thought the memory issues were related to mmap issues between libtorrent v1 and v2. However, I've tried running my qBittorrent containers all with v4.3.9, v.4.4.5 and v.4.5.2 (libtorrent v1 and v2), and still get OOM errors after a couple days.
In debugging, I found that disconnecting my Radarr/Sonarr instances from qBittorrent kept memory usage stable and I suspect that querying the web API can cause memory leaks.
Example To demonstrate the issue, I've created a simulated example where I create three new qBittorrent test instances. Then I loaded them with 10, 100, and 1000 torrents, respectively. Then I query each container's web API for a list of torrents one hundred times:
Note that a fresh container starts at 15MiB, but after querying the APIs,
qbittorrent-1000
has 500MiB memory usage compared toqbittorrent-10
30MiB memory usage. I've included more details on how to reproduce similar results below. I've also tried to manually clear RAM cache by runningecho 3 > /proc/sys/vm/drop_caches
which does nothing. Continuing to runfetch-torrents.py
will eventually cause the container to crash due to out of memory issues.Steps to reproduce
docker-compose.yaml:
fetch-torrents.py:
add-torrents.py:
Full steps to reproduce. I am using two Python libraries
torf-cli
to locally edit .torrent files andqbittorrent-api
to query the API. I am creating a .torrent file off a simple .txt file. I generate a thousand .torrent files by just modifying thesource
field in the metainfo field of the .torrent file.