diff options
| author | Randy Döring <30527984+radoering@users.noreply.github.com> | 2023-03-12 18:23:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-12 10:23:07 -0700 |
| commit | d48565f2a7a3096fd45bf11ca194ea095bdae9ac (patch) | |
| tree | 1fc1d6df98424cf971b2cffc06495e61b77e6923 /src | |
| parent | e2a9ee59e58c48a663bb435dbeb36a160272f695 (diff) | |
| download | virtualenv-d48565f2a7a3096fd45bf11ca194ea095bdae9ac.tar.gz | |
Make `ReentrantFileLock` thread-safe and, thereby, fix race condition in `virtualenv.cli_run` (#2517)
Diffstat (limited to 'src')
| -rw-r--r-- | src/virtualenv/util/lock.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/virtualenv/util/lock.py b/src/virtualenv/util/lock.py index 8d7215e..cf026f4 100644 --- a/src/virtualenv/util/lock.py +++ b/src/virtualenv/util/lock.py @@ -23,13 +23,16 @@ class _CountedFileLock(FileLock): self.thread_safe = RLock() def acquire(self, timeout=None, poll_interval=0.05): - with self.thread_safe: - if self.count == 0: - super().acquire(timeout, poll_interval) - self.count += 1 + if not self.thread_safe.acquire(timeout=-1 if timeout is None else timeout): + raise Timeout(self.lock_file) + if self.count == 0: + super().acquire(timeout, poll_interval) + self.count += 1 def release(self, force=False): with self.thread_safe: + if self.count > 0: + self.thread_safe.release() if self.count == 1: super().release(force=force) self.count = max(self.count - 1, 0) |
