Skip to content

Commit

Permalink
Improve handling of unresolvable news servers (#2347)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
puzzledsab committed Nov 25, 2022
1 parent 45d232e commit ee2b2b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 10 additions & 12 deletions sabnzbd/downloader.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions sabnzbd/newswrapper.py
Expand Up @@ -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):
Expand Down

0 comments on commit ee2b2b2

Please sign in to comment.