From 71122f941f99cea6001c143feedf34a8dbb2a2a2 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 26 May 2023 02:44:37 +0000 Subject: [PATCH] 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 Commit-Queue: Josip Sokcevic Tested-by: Josip Sokcevic Reviewed-by: Gavin Mak --- subcmds/sync.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index 9ae8a4ce..0e4f34c0 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -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}"