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

Sonarr queue cleaning failed - List out of range #36

Closed
TheNetworkGuy opened this issue Feb 19, 2024 · 17 comments · Fixed by #39
Closed

Sonarr queue cleaning failed - List out of range #36

TheNetworkGuy opened this issue Feb 19, 2024 · 17 comments · Fixed by #39

Comments

@TheNetworkGuy
Copy link
Contributor

Hey, cool project!

Running into the following issue:

Queue cleaning failed on Sonarr. (File: remove_slow.py / Line: 21 / Error Message: list index out of range / Error Type: <class 'IndexError'>)

If you need any extra debug stuff feel free to ask :) I'm running with the latest version of the script (at the time of writing) with a standard docker-compose setup. Running develop version of Sonarr and latest of qBittorrent.

@ManiMatter
Copy link
Owner

Hi
Could you switch to loglevel DEBUG please and paste the result to pastebin?

do you know when this occurs?

@TheNetworkGuy
Copy link
Contributor Author

Sure, i'll post the debug output to pastebin.

Occurs right away when first starting the container. Other services such as Radarr do not show this error.

@ManiMatter
Copy link
Owner

Pls only leave the REMOVE_STALLED on true and the others on false; spares me the irrelevant logs
Thx

@TheNetworkGuy
Copy link
Contributor Author

TheNetworkGuy commented Feb 19, 2024

All checks disabled exect for slow check. Test = false.

https://pastebin.com/hL21fmNj

decluttarr:
image: ghcr.io/manimatter/decluttarr:latest
environment:
- TZ=Europe/Amsterdam
- PUID=1000
- PGID=1000
# General
- LOG_LEVEL=DEBUG
# - TEST_RUN=True
# Features
- REMOVE_TIMER=3
- REMOVE_FAILED=False
- REMOVE_METADATA_MISSING=False
- REMOVE_MISSING_FILES=False
- REMOVE_ORPHANS=False
- REMOVE_SLOW=True
- REMOVE_STALLED=False
- REMOVE_UNMONITORED=False
- MIN_DOWNLOAD_SPEED=100
- PERMITTED_ATTEMPTS=3
- NO_STALLED_REMOVAL_QBIT_TAG=Don't Kill
- IGNORE_PRIVATE_TRACKERS=True
# Radarr
- RADARR_URL=http://radarr:7878
- RADARR_KEY=
# Sonarr
- SONARR_URL=http://sonarr:8989
- SONARR_KEY=
# qBittorrent
- QBITTORRENT_URL=http://qbittorrent:8081
- QBITTORRENT_USERNAME=
- QBITTORRENT_PASSWORD=

@ManiMatter
Copy link
Owner

Thanks, that's helpful.

Good news is: I can tell exactly in which 20+- lines the bug occurs, but I need more granular logs.
I added that into the :dev version, can you please switch to that and provide the logs again?

If it's possible, would you be able to also share them with timestamp? (I use amir20/dozzle:latest for that)

@TheNetworkGuy
Copy link
Contributor Author

I can share everything and downloaded Dozzle :) However get the following output back and i presume that this isn't what you inteded to happen with the dev version? (guess on my end, if this is supposed to be the output then i can share my full Dozzle output.)

downloader-decluttarr-1  | [WARNING]: >>> Queue cleaning failed on Sonarr. (File: remove_slow.py / Line: 21 / Error Message: name 'NAME' is not defined / Error Type: <class 'NameError'>)
downloader-decluttarr-1  | [DEBUG]: IndexError: list index out of range
downloader-decluttarr-1  | 
downloader-decluttarr-1  | During handling of the above exception, another exception occurred:
downloader-decluttarr-1  | 
downloader-decluttarr-1  | NameError: name 'NAME' is not defined
downloader-decluttarr-1  | 

@ManiMatter
Copy link
Owner

My bad, sry! Can you pls try again, the new issue I had introduced should be fixed and we should now see the logs

@TheNetworkGuy
Copy link
Contributor Author

https://pastebin.com/xE9kvzEh

Seems like an expected list variable is not actually a list and instead is declared as a None. I'll take a look at the code as well to check if i can see something obvious :)

@ManiMatter
Copy link
Owner

ManiMatter commented Feb 20, 2024

My hypothesis: the qbit call does not find the hash, ie when already removed in the meantime, probs need to deal with that scenario

can you paste a screenshot of qbit at the moment decluttarr crashes; pls make sure we see the hash if the torrent that breaks it is there

@TheNetworkGuy
Copy link
Contributor Author

This could be the problem yeah. I can see the same error appearing with Radarr as well and since that list is shorter i used that to compare the setups.

[{'downloadId': '590DCD68719882177C9A56FEEF596E7804A0BA36', 'downloadTitle': 'The Prestige 2006.4K.HDR.DV.2160p.BDRemux Ita Eng x265-NAHOM', 'IDs': [1160672294]}, {'downloadId': 'SABnzbd_nzo_5qaahqic', 'downloadTitle': 'No Escape 2015 BluRay 1080p REMUX AVC DTS-HD MA 5.1-LEGi0N', 'IDs': [1433654272]}]

2 entries, one of which is in qBittorrent (verified with the hash.) The other one is downloading in Sabnzbd. Could the Sabnzbd entry be a problem? Since the queue won't be properly generated with only items from qBittorrent.

@TheNetworkGuy
Copy link
Contributor Author

TheNetworkGuy commented Feb 20, 2024

Just ran this code and seems to be working for both Radarr as well as Sonarr. Its dirty and needs some proper error handeling instead of a hardcoded "SABnzbd_", probably won't work in use-cases with NZBget and other clients. Or query the API of Radarr and Sonarr for downloads which are only communicated towards qBittorrent. Anyhow:

async def remove_slow(settings_dict, BASE_URL, API_KEY, NAME, deleted_downloads, defective_tracker, protectedDownloadIDs, privateDowloadIDs, download_sizes_tracker):
    # Detects slow downloads and triggers delete. Adds to blocklist
    try:
        failType = 'slow'
        queue = await get_queue(BASE_URL, API_KEY)
        logger.debug('remove_slow/queue IN: %s', formattedQueueInfo(queue))
        if not queue: return 0
        # Find items affected
        affectedItems = []
        alreadyCheckedDownloadIDs = []
        nzb_clients_id_prefix = ('SABnzbd_')
        for queueItem in queue['records']:
            if 'downloadId' in queueItem and 'size' in queueItem and 'sizeleft' in queueItem and 'status' in queueItem:
                if queueItem['downloadId'] not in alreadyCheckedDownloadIDs:
                    # Check if the downloadID is from an NZB client: if so skip this download entry since its not in the torrent client.
                    if queueItem['downloadId'].startswith(nzb_clients_id_prefix ):
                        continue
                    alreadyCheckedDownloadIDs.append(queueItem['downloadId']) # One downloadId may occur in multiple queueItems - only check once for all of them per iteration
                    # determine if the downloaded bit on average between this and the last iteration is greater than the min threshold
                    downloadedSize, previousSize, increment, speed = await getDownloadedSize(settings_dict, queueItem, download_sizes_tracker, NAME)

worked for me. Simple continue statement.

@TheNetworkGuy
Copy link
Contributor Author

Check. I've updated the code above so that it reflects a bit more of a permanent solution. However i would recommend having the variable nzb_clients_id_prefix in a more global place since it might come in use with multiple functions / classes.

@ManiMatter
Copy link
Owner

Check the getDownloadedSize()
Can you look at the queueitem and see if theres sn attribute that tells which downloadclient it is?

If not qbit default back to using progressinfo from the arrapp.. (there‘s a confition in the beginning already that checks if qbit is even specified; could that be extdnded)?

@TheNetworkGuy
Copy link
Contributor Author

TheNetworkGuy commented Feb 20, 2024

This seems useful...

{'seriesId': 20, 'episodeId': 2201, 'seasonNumber': 4, 'languages': [{'id': 1, 'name': 'English'}], 'quality': {'quality': {'id': 2, 'name': 'DVD', 'source': 'dvd', 'resolution': 480}, 'revision': {'version': 1, 'real': 0, 'isRepack': False}}, 'customFormats': [], 'customFormatScore': 0, 'size': 353558855, 'title': 'Flashpoint.S04E17.DVDRip.X264-OSiTV', 'sizeleft': 353558855, 'added': '2024-02-19T14:47:53Z', 'status': 'paused', 'trackedDownloadStatus': 'ok', 'trackedDownloadState': 'downloading', 'statusMessages': [], 'downloadId': 'SABnzbd_nzo_lpu5uxe0', 'protocol': 'usenet', 'downloadClient': 'Sabnzbd', 'downloadClientHasPostImportCategory': False, 'indexer': 'altHUB (Prowlarr)', 'episodeHasFile': False, 'id': 1685199207}

The value of a torrent based download is "torrent". This seems like a great way to filter out usenet downloads :)

async def remove_slow(settings_dict, BASE_URL, API_KEY, NAME, deleted_downloads, defective_tracker, protectedDownloadIDs, privateDowloadIDs, download_sizes_tracker):
    # Detects slow downloads and triggers delete. Adds to blocklist
    try:
        failType = 'slow'
        queue = await get_queue(BASE_URL, API_KEY)
        logger.debug('remove_slow/queue IN: %s', formattedQueueInfo(queue))
        if not queue: return 0
        # Find items affected
        affectedItems = []
        alreadyCheckedDownloadIDs = []
        for queueItem in queue['records']:
            # Check if download protocol is torrent. If not, skip download
            if 'protocol' in queueItem:
                if not queueItem['protocol'] == 'torrent':
                    continue
            if 'downloadId' in queueItem and 'size' in queueItem and 'sizeleft' in queueItem and 'status' in queueItem:

I've created #37 to fix this issue for the slow download detection.

@ManiMatter
Copy link
Owner

Thx for the pr; does dev image work for you now?

@TheNetworkGuy
Copy link
Contributor Author

Just pulled the latest :dev with docker compose and works like a charm! :)

@ManiMatter
Copy link
Owner

Sweet. Pr‘ing to main then

@ManiMatter ManiMatter linked a pull request Feb 20, 2024 that will close this issue
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 a pull request may close this issue.

2 participants