From a2484b305374d275763e909fbda36a2b79338e30 Mon Sep 17 00:00:00 2001 From: FYY Date: Tue, 19 Sep 2023 20:01:23 -0400 Subject: [PATCH] Fix file locks in NFS-mounted directories (#517) Fix #515. --- src/petals/server/throughput.py | 2 +- src/petals/utils/disk_cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/petals/server/throughput.py b/src/petals/server/throughput.py index bf71f44..c42bdb9 100644 --- a/src/petals/server/throughput.py +++ b/src/petals/server/throughput.py @@ -56,7 +56,7 @@ def get_server_throughput( # We use the system-wide lock since only one process at a time can measure the host throughput os.makedirs(lock_path.parent, exist_ok=True) - with open(lock_path, "wb") as lock_fd: + with open(lock_path, "wb+") as lock_fd: logger.info("Loading throughput info") fcntl.flock(lock_fd.fileno(), fcntl.LOCK_EX) # The OS will release the lock when lock_fd is closed or the process is killed diff --git a/src/petals/utils/disk_cache.py b/src/petals/utils/disk_cache.py index a26a0f5..5de47c8 100644 --- a/src/petals/utils/disk_cache.py +++ b/src/petals/utils/disk_cache.py @@ -22,7 +22,7 @@ def _blocks_lock(cache_dir: Optional[str], mode: int): lock_path = Path(cache_dir, BLOCKS_LOCK_FILE) os.makedirs(lock_path.parent, exist_ok=True) - with open(lock_path, "wb") as lock_fd: + with open(lock_path, "wb+") as lock_fd: fcntl.flock(lock_fd.fileno(), mode) # The OS will release the lock when lock_fd is closed or the process is killed yield