mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
[gsutil] Fix race when downloading gsutil
If gsutil is not downloaded, and if gsutil (or download_from_google_storage) is called concurrently with n>2, it's possible that those processes are doing the same work. There is also a critical point where gsutil.py can fail with: Destination path '/depot_tools_path/external_bin/gsutil/gsutil_4.68/d' already exists error. To avoid this problem, use FS locking around code that manipulates with files. R=jojwang@google.com Bug: 338040708 Change-Id: Ib83aaa1e09628f878e512d79f2fa5221c2bcfd37 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5502531 Reviewed-by: Joanna Wang <jojwang@chromium.org> Commit-Queue: Joanna Wang <jojwang@chromium.org> Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
@@ -80,14 +80,16 @@ def _try_lock(lockfile):
|
||||
def _lock(path, timeout=0):
|
||||
"""_lock returns function to release the lock if locking was successful.
|
||||
|
||||
_lock also implements simple retry logic."""
|
||||
_lock also implements simple retry logic.
|
||||
NOTE: timeout value doesn't include time it takes to aquire lock, just
|
||||
overall sleep time."""
|
||||
elapsed = 0
|
||||
sleep_time = 0.1
|
||||
while True:
|
||||
try:
|
||||
return _try_lock(path + '.locked')
|
||||
except (OSError, IOError) as e:
|
||||
if elapsed < timeout:
|
||||
sleep_time = min(10, timeout - elapsed)
|
||||
logging.info(
|
||||
'Could not create git cache lockfile; '
|
||||
'will retry after sleep(%d).', sleep_time)
|
||||
|
||||
Reference in New Issue
Block a user