Skip to content

Commit 768825e

Browse files
committed
[casc] Fix host shuffling in URL fetch retries
1 parent a5a05f0 commit 768825e

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

casc_extract/casc.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def __init__(self, options):
512512

513513
def get_url(self, url, headers=None):
514514
attempt = 0
515-
maxAttempts = 5
515+
maxAttempts = 6
516516
while attempt < maxAttempts:
517517
r = None
518518
try:
@@ -538,26 +538,18 @@ def get_url(self, url, headers=None):
538538
# try a random, different CDN host
539539
# TODO: clean this up
540540
# depending on how this gets called the cdn_host is buried in the build object
541-
if self.cdn_host:
542-
if len(self.cdn_host):
541+
search_hosts = self.cdn_host or self.build.cdn_host
542+
if search_hosts:
543+
if len(search_hosts):
543544
cur_host = ''
544-
for host in self.cdn_host:
545-
if url.find(host):
546-
cur_host = host
547-
if cur_host:
548-
other_hosts = [host for host in self.cdn_host if host != cur_host]
549-
url = url.replace(cur_host, random.choice(other_hosts))
550-
time.sleep(2**attempt)
551-
attempt += 1
552-
elif self.build.cdn_host:
553-
if len(self.build.cdn_host):
554-
cur_host = ''
555-
for host in self.build.cdn_host:
556-
if url.find(host):
545+
for host in search_hosts:
546+
if host in url:
557547
cur_host = host
548+
558549
if cur_host:
559-
other_hosts = [host for host in self.build.cdn_host if host != cur_host]
560-
url = url.replace(cur_host, random.choice(other_hosts))
550+
other_hosts = [host for host in search_hosts if host != cur_host]
551+
try_host = other_hosts[attempt % len(other_hosts)]
552+
url = url.replace(cur_host, try_host)
561553
time.sleep(2**attempt)
562554
attempt += 1
563555
else:

0 commit comments

Comments
 (0)