sync: Handle race condition when reading active jobs
It's possible that number of jobs is more than 0 when we
check length, but in the meantime number of jobs drops to
0. In that case, we are working with float(inf) which
causes other problems
Bug: 284383869
Change-Id: I5d070d1be428f8395df7fde8ca84866db46f2100
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/375134
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Tested-by: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 9ae8a4c..0e4f34c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -677,9 +677,6 @@
cls.ssh_proxy = ssh_proxy
def _GetSyncProgressMessage(self):
- if len(self._sync_dict) == 0:
- return None
-
earliest_time = float("inf")
earliest_proj = None
for project, t in self._sync_dict.items():
@@ -687,6 +684,9 @@
earliest_time = t
earliest_proj = project
+ if not earliest_proj:
+ return None
+
elapsed = time.time() - earliest_time
jobs = jobs_str(len(self._sync_dict))
return f"{jobs} | {elapsed_str(elapsed)} {earliest_proj}"