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>
This commit is contained in:
Josip Sokcevic 2023-05-26 02:44:37 +00:00 committed by LUCI
parent 07a4529278
commit 71122f941f

View File

@ -677,9 +677,6 @@ later is required to fix a server side protocol bug.
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 @@ later is required to fix a server side protocol bug.
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}"