ManiMatter / decluttarr

Watches radarr, sonarr, lidarr, readarr and whisparr download queues and removes downloads if they become stalled or no longer needed.
GNU General Public License v3.0
99 stars 15 forks source link

Remove Slow Downloads stuck on 0kb size / MetaData Not being detected as slow. #119

Open slkiny opened 3 weeks ago

slkiny commented 3 weeks ago
image

Currently these use cases fail to be detected. For torrents which are not very popular you may fail to even download the magnet file.

image

Instead it was detected as a big download that might be moving soon... This will fix the issue, and ensure that something is downloaded.

Example JSON of a Magnet File that is not downloaded.

[INFO]: {'seriesId': 90, 'episodeId': 8097, 'seasonNumber': 4, 'languages': [], 'quality': {'quality': {'id': 5, 'name': 'WEBDL-720p', 'source': 'web', 'resolution': 720}, 'revision': {'version': 1, 'real': 0, 'isRepack': False}}, 'customFormats': [], 'customFormatScore': 0, 'size': 0, 'title': 'fc2e9e29471ed570771be8dfa157c512fad6e6eb', 'sizeleft': 0, 'added': '2024-06-10T00:16:14Z', 'status': 'downloading', 'trackedDownloadStatus': 'ok', 'trackedDownloadState': 'downloading', 'statusMessages': [], 'downloadId': 'FC2E9E29471ED570771BE8DFA157C512FAD6E6EB', 'protocol': 'torrent', 'downloadClient': 'qbit', 'downloadClientHasPostImportCategory': False, 'indexer': 'TorrentDownload (Prowlarr)', 'episodeHasFile': False, 'id': 333611039}

image

Example logs when it is working.

ManiMatter commented 2 weeks ago

Hi @slkiny

welcome and thank you for your PR.

I am not sure I understand what is happening here. On the picture below, the downloads are in "Downloading metatada" stage. On the json that you posted, they are in 'status': 'downloading', 'trackedDownloadStatus': 'ok', 'trackedDownloadState': 'downloading', 'statusMessages': []. So no mentioning of metdata.

image

I think I would not want to remove these metadata torrents in the slow-check. There's a specific script for that, and I would suggest that we amend that one if it fails to capture metadata items.

In the file "remove_metadata_missing.py", you see that this condition is there to capture items that fail to grab metadata: if queueItem['status'] == 'queued' and queueItem['errorMessage'] == 'qBittorrent is downloading metadata':. However, that status is "queued", not downloading.

I'd like to understand why your queue-json does not say anything about metadata. Could you post the properties of the torrent that you see in qbit? Also, for how long are they in "downloading" state as opposed to "queued"?

Also, to make sure these metadata torrents (in downloading state) are not coming up in the slow check, I think what we can easily do is to change the below to if queueItem['status'] == 'downloading' and queueItem['size']:

https://github.com/ManiMatter/decluttarr/blob/2ee86d35914d24318b83c0672add7954571c9e0e/src/jobs/remove_slow.py#L30

slkiny commented 2 weeks ago

Thanks for the feedback, yeah this seems like an edge case either the metadata missing or slow could detect. Maybe both..?

tldr; I think overall its tricky since its a download failing... Overall i think the root cause is more about detecting a torrent either being stuck (slow) downloading due to 0kb max size (bad metadata). Which to me should may be caught in both the slow and the metadata system..

I don't have a personal preference, but seems that you'd prefer it to be in the metadata handler.

I saw the metadata code was more about queued or errors. While this metadata seems to be the system thinks it can download it but cannot finish downloading it so I made the change in the slow download section.

Regardless of the final placement, another phrasing of this issue could be

"To Detect (slow) downloads that are not progressing 0kb; due to possible (metadata) data issues and have a size of 0 bytes for over X minutes, and remove those"

With that insight in mind is why I picked to put it in slow download, but i can see about moving it if you feel strongly about it.

I could imagine maybe a malfored metadata might also equal out to 0 byte size as well, so I am curious which was the root cause. But detecting 0 bytes/no size in general seems like a good thing to check for in many places.. since some people might not even enabled metacheck but might have slow check on hmm....

As a side note, i wanted to handle this in specific log message to the user. Since it helps to diagnose that the issue was due to metadata or torrent failing to download.

slkiny commented 2 weeks ago

If you agree with the above statement we can modify the statement of the logs to be more about, a download with 0 size was detected. This looks malformed and if it doesn't progress or get a size > 0 soon we will terminate it etc..

changed wording.


  else:
      # MetaData is too slow to download/is stuck
      logger.info('>>> Detected %s download that is 0kb is slow or stuck. (Failed Metadata or Torrent) Adding to queue.',queueItem['title'])    
      affectedItems.append(queueItem)
      continue

By the way thanks for this project, I made my own prior. And found this to be a lot better :) I've had alot of oddities with qbit, which is why i prefer defense in depth so just check everything everywhere 😆

ManiMatter commented 2 weeks ago

Hi

thanks for your thoughts.

I am still unsure that I understand why this scenario even occurs. On the qbit screenshot that you posted the status is ‚Downloading metadata‘, but the json that you posted does not carry the status.

For me, slow check is for stuff in progress; metadata is a different gig, hence why I would put it over there. But rather to piecemeal together that the downloading of metadata is taking forever, it would be great if that status came through in the queue response. Maybe the sonarr team could add it and then we add that specific status to the metadata check?

ManiMatter commented 1 week ago

I still think we need to get to the bottom why your queue response is ‚downloading‘ (instead of ‚queued‘) and says nothing about metadata.

On the json that you posted, they are in 'status': 'downloading', 'trackedDownloadStatus': 'ok', 'trackedDownloadState': 'downloading', 'statusMessages': []. So no mentioning of metdata.

After all, there are other downloads that are marked like that when downloading metadata.

https://github.com/ManiMatter/decluttarr/blob/2ee86d35914d24318b83c0672add7954571c9e0e/src/jobs/remove_metadata_missing.py#L17

Maybe worthwhile asking the sonarr team?

What they probably need from you are the response of the /properties call in qbit for that specific torrent, so they see what the status etc is.

slkiny commented 1 week ago

Yeah I tried looking into it more, but its still a curious bug; maybe related to how i tend to Force Download things possibly? I moved it to the metadata piece as suggested, but i dont see any harm in having it as a double check in general.

Also i added a shared func to check if the keys exist in a dict. A bit more readable.

ManiMatter commented 6 days ago

I think you should ask sonarr why the metadata state is not in errorMessage, and why the state is downloading, not queued. Because that is how it normally is; if they then might realize that they have not added the metadata state for downloading state, they add it and we use that.

Refer to this: https://github.com/Sonarr/Sonarr/issues/5940

Essentially what they achieved here is to differentiate between truly queued downloads, and those fetching metadata, by adding "statusMessages": ["qBittorrent is downloading metadata"].

It seems that you have hit a scenario where the status is not queued but downloading and the same differentiation is required. Maybe they can build on what they have already done for queued?

ManiMatter commented 21 hours ago

@slkiny - are you still looking into this?