contains_revision should respect lock_timeout attached by users

BUG=449182250,407051026
Change-Id: Icee1725cb0c0f0f4b6a757c4b381d6589486e40d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7000923
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
This commit is contained in:
Xinan Lin
2025-10-07 13:56:25 -07:00
committed by LUCI CQ
parent d04b267a2d
commit 66a66dd901
2 changed files with 12 additions and 14 deletions

View File

@@ -313,22 +313,14 @@ class Mirror(object):
self.Rename(tempdir, directory)
return True
def contains_revision(self, revision):
def contains_revision(self, revision, timeout):
if not self.exists():
return False
# This will raise LockError(), if another process is
# 1) sync()-ing or
# 2) calling contains_revision().
#
# In case (1), the caller is responsible for handling the LockError().
# As per (2), the below gives 20 secs timeout just to cover most
# practical cases.
#
# Ideally, read-write locks should be used, Then, the below would
# - acquire the read lock immediately or
# - raise LockError() if there is an ongoing sync()-ing.
with lockfile.lock(self.mirror_path, timeout=20):
with lockfile.lock(self.mirror_path, timeout=timeout):
# If the sentinent file exists at this point, it indicates that
# the bootstrapping process was interrupted, leaving the cache
# entries in a bad state.