summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-04-15 02:06:28 -0400
committerMike Frysinger <vapier@google.com>2021-04-19 16:42:06 +0000
commit6823bc269d63a66c8813803f1057eac328bc3ccb (patch)
treeca106a92351e409f226ed55a881b4304580458fc /project.py
parentad8aa6977248c46669575282302f5de90043fdf0 (diff)
downloadgit-repo-6823bc269d63a66c8813803f1057eac328bc3ccb.tar.gz
sync: cleanup sleep+retry logic a bitv2.14
Make sure we print a message whenever we retry so it's clear to the user why repo is pausing for a long time, and why repo might have passed even though it displayed some errors earlier. Also unify the sleep logic so we don't have two independent methods. This makes it easier to reason about. Also don't sleep if we're in the last iteration of the for loop. It doesn't make sense to and needlessly slows things down when there are real errors. Bug: https://crbug.com/gerrit/12494 Change-Id: Ifceace5b2dde75c2dac39ea5388527dd37376336 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/303402 Reviewed-by: Sam Saccone 🐐 <samccone@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/project.py b/project.py
index 9517c5ab..1e31a20a 100644
--- a/project.py
+++ b/project.py
@@ -2175,19 +2175,13 @@ class Project(object):
2175 elif (gitcmd.stdout and 2175 elif (gitcmd.stdout and
2176 'error:' in gitcmd.stdout and 2176 'error:' in gitcmd.stdout and
2177 'HTTP 429' in gitcmd.stdout): 2177 'HTTP 429' in gitcmd.stdout):
2178 if not quiet: 2178 # Fallthru to sleep+retry logic at the bottom.
2179 print('429 received, sleeping: %s sec' % retry_cur_sleep, 2179 pass
2180 file=sys.stderr)
2181 time.sleep(retry_cur_sleep)
2182 retry_cur_sleep = min(retry_exp_factor * retry_cur_sleep,
2183 MAXIMUM_RETRY_SLEEP_SEC)
2184 retry_cur_sleep *= (1 - random.uniform(-RETRY_JITTER_PERCENT,
2185 RETRY_JITTER_PERCENT))
2186 continue
2187 2180
2188 # If this is not last attempt, try 'git remote prune'. 2181 # Try to prune remote branches once in case there are conflicts.
2189 elif (try_n < retry_fetches - 1 and 2182 # For example, if the remote had refs/heads/upstream, but deleted that and
2190 gitcmd.stdout and 2183 # now has refs/heads/upstream/foo.
2184 elif (gitcmd.stdout and
2191 'error:' in gitcmd.stdout and 2185 'error:' in gitcmd.stdout and
2192 'git remote prune' in gitcmd.stdout and 2186 'git remote prune' in gitcmd.stdout and
2193 not prune_tried): 2187 not prune_tried):
@@ -2197,6 +2191,8 @@ class Project(object):
2197 ret = prunecmd.Wait() 2191 ret = prunecmd.Wait()
2198 if ret: 2192 if ret:
2199 break 2193 break
2194 output_redir.write('retrying fetch after pruning remote branches')
2195 # Continue right away so we don't sleep as we shouldn't need to.
2200 continue 2196 continue
2201 elif current_branch_only and is_sha1 and ret == 128: 2197 elif current_branch_only and is_sha1 and ret == 128:
2202 # Exit code 128 means "couldn't find the ref you asked for"; if we're 2198 # Exit code 128 means "couldn't find the ref you asked for"; if we're
@@ -2206,9 +2202,17 @@ class Project(object):
2206 elif ret < 0: 2202 elif ret < 0:
2207 # Git died with a signal, exit immediately 2203 # Git died with a signal, exit immediately
2208 break 2204 break
2205
2206 # Figure out how long to sleep before the next attempt, if there is one.
2209 if not verbose: 2207 if not verbose:
2210 print('\n%s:\n%s' % (self.name, gitcmd.stdout), file=sys.stderr) 2208 output_redir.write('\n%s:\n%s' % (self.name, gitcmd.stdout), file=sys.stderr)
2211 time.sleep(random.randint(30, 45)) 2209 if try_n < retry_fetches - 1:
2210 output_redir.write('sleeping %s seconds before retrying' % retry_cur_sleep)
2211 time.sleep(retry_cur_sleep)
2212 retry_cur_sleep = min(retry_exp_factor * retry_cur_sleep,
2213 MAXIMUM_RETRY_SLEEP_SEC)
2214 retry_cur_sleep *= (1 - random.uniform(-RETRY_JITTER_PERCENT,
2215 RETRY_JITTER_PERCENT))
2212 2216
2213 if initial: 2217 if initial:
2214 if alt_dir: 2218 if alt_dir: