From ee2b2b2c3a0f8f215405e7f58f63e042a51b8896 Mon Sep 17 00:00:00 2001 From: puzzledsab <50911832+puzzledsab@users.noreply.github.com> Date: Fri, 25 Nov 2022 22:47:58 +0100 Subject: [PATCH] Improve handling of unresolvable news servers (#2347) * Trying to find cause of git bug #2345 * Try to find IP using happyeyeballs first, fall back to default if it fails * Fix mistake * Add host name to connection error message * Always debug log IP address --- sabnzbd/downloader.py | 22 ++++++++++------------ sabnzbd/newswrapper.py | 7 +++++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/sabnzbd/downloader.py b/sabnzbd/downloader.py index 656e32cbd4e..9f9f8e8010f 100644 --- a/sabnzbd/downloader.py +++ b/sabnzbd/downloader.py @@ -178,23 +178,21 @@ def hostip(self) -> str: # Determine IP ip = self.host if self.info: - if cfg.load_balancing() == 0 or len(self.info) == 1: + # Check this first so we can fall back to default method if it returns None. + if len(self.info) > 1 and cfg.load_balancing() == 2: + # RFC6555 / Happy Eyeballs: + ip = happyeyeballs(self.host, port=self.port) + if not ip: + # nothing returned, so there was a connection problem + logging.debug("%s: No successful IP connection was possible using happyeyeballs", self.host) + if not ip or cfg.load_balancing() == 0 or len(self.info) == 1: # Just return the first one, so all next threads use the same IP ip = self.info[0][4][0] - logging.debug("%s: Connecting to address %s", self.host, ip) elif cfg.load_balancing() == 1: # Return a random entry from the possible IPs rnd = random.randint(0, len(self.info) - 1) ip = self.info[rnd][4][0] - logging.debug("%s: Connecting to address %s", self.host, ip) - elif cfg.load_balancing() == 2: - # RFC6555 / Happy Eyeballs: - ip = happyeyeballs(self.host, port=self.port) - if ip: - logging.debug("%s: Connecting to address %s", self.host, ip) - else: - # nothing returned, so there was a connection problem - logging.debug("%s: No successful IP connection was possible", self.host) + logging.debug("%s: Connecting to address %s", self.host, ip) return ip def deactivate(self): @@ -968,7 +966,7 @@ def __reset_nw( nw.article.tries += 1 # Do we discard, or try again for this server - if not retry_article or nw.article.tries > cfg.max_art_tries(): + if not retry_article or (not nw.server.required and nw.article.tries > cfg.max_art_tries()): # Too many tries on this server, consider article missing self.decode(nw.article, None) nw.article.tries = 0 diff --git a/sabnzbd/newswrapper.py b/sabnzbd/newswrapper.py index fdcf6600fcf..bca3ba628ab 100644 --- a/sabnzbd/newswrapper.py +++ b/sabnzbd/newswrapper.py @@ -397,10 +397,13 @@ def error(self, error: OSError): raise socket.error(errno.ECONNREFUSED, str(error)) else: msg = "Failed to connect: %s" % (str(error)) - msg = "%s %s@%s:%s" % (msg, self.nw.thrdnum, self.host, self.nw.server.port) + msg = "%s %s:%s (%s)" % (msg, self.nw.server.host, self.nw.server.port, self.host) self.error_msg = msg self.nw.server.next_busy_threads_check = 0 - logging.info(msg) + if self.nw.server.warning == msg: + logging.info(msg) + else: + logging.warning(msg) self.nw.server.warning = msg def __repr__(self):