Skip to content

Commit

Permalink
Do a more thorough check when a bad try_list is detected (#2330)
Browse files Browse the repository at this point in the history
* Do a more thorough check when a bad try_list is detected

* Improve idle job check and fix DNS lookup problem

* Loop through copy of article list and move nzf.reset_try_list below the article check

Closes #2320
  • Loading branch information
puzzledsab committed Nov 16, 2022
1 parent 7aa8e3d commit fd3ece3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions sabnzbd/downloader.py
Expand Up @@ -230,6 +230,7 @@ def _request_info_internal(self):
self.info = get_server_addrinfo(self.host, self.port)
if not self.info:
self.bad_cons += self.threads
self.info = False
else:
self.bad_cons = 0
self.request = False
Expand Down
17 changes: 15 additions & 2 deletions sabnzbd/nzbqueue.py
Expand Up @@ -883,9 +883,14 @@ def is_empty(self) -> bool:
def stop_idle_jobs(self):
"""Detect jobs that have zero files left and send them to post processing"""
# Only check servers that are active
nr_servers = len([server for server in sabnzbd.Downloader.servers[:] if server.active])
active_servers = [server for server in sabnzbd.Downloader.servers[:] if server.active]
nr_servers = len(active_servers)
empty = []

if nr_servers <= 0:
logging.debug("Skipping stop_idle_jobs because no servers are active")
return

for nzo in self.__nzo_list:
if not nzo.futuretype and not nzo.files and nzo.status not in (Status.PAUSED, Status.GRABBING):
logging.info("Found idle job %s", nzo.final_name)
Expand All @@ -896,8 +901,16 @@ def stop_idle_jobs(self):
if len(nzo.try_list) >= nr_servers:
# Maybe the NZF's need a reset too?
for nzf in nzo.files:
if nzo.removed_from_queue:
break

if len(nzf.try_list) >= nr_servers:
# We do not want to reset all article trylists, they are good
# Check for articles where all active servers have already been tried
for article in nzf.articles[:]:
if article.all_servers_in_try_list(active_servers):
sabnzbd.NzbQueue.register_article(article, success=False)
nzo.increase_bad_articles_counter("missing_articles")

logging.info("Resetting bad trylist for file %s in job %s", nzf.filename, nzo.final_name)
nzf.reset_try_list()

Expand Down
10 changes: 9 additions & 1 deletion sabnzbd/nzbstuff.py
Expand Up @@ -112,11 +112,19 @@ class TryList:
def __init__(self):
self.try_list: List[Server] = []

def server_in_try_list(self, server: Server):
def server_in_try_list(self, server: Server) -> bool:
"""Return whether specified server has been tried"""
with TRYLIST_LOCK:
return server in self.try_list

def all_servers_in_try_list(self, servers: List[Server]) -> bool:
"""Check if all servers have been tried"""
with TRYLIST_LOCK:
for server in servers:
if not server in self.try_list:
return False
return True

def add_to_try_list(self, server: Server):
"""Register server as having been tried already"""
with TRYLIST_LOCK:
Expand Down

0 comments on commit fd3ece3

Please sign in to comment.