Read-only locks should close fd before opening for write. (#1906)
- Fixes bad file descriptor error in lock acquire, #1904 - Fix bug introduced in previous PR #1857 - Backported fix from soon-to-be merged fine-grained DB locking branch.
This commit is contained in:
@@ -69,6 +69,14 @@ def _lock(self, op, timeout):
|
||||
start_time = time.time()
|
||||
while (time.time() - start_time) < timeout:
|
||||
try:
|
||||
# If this is already open read-only and we want to
|
||||
# upgrade to an exclusive write lock, close first.
|
||||
if self._fd is not None:
|
||||
flags = fcntl.fcntl(self._fd, fcntl.F_GETFL)
|
||||
if op == fcntl.LOCK_EX and flags | os.O_RDONLY:
|
||||
os.close(self._fd)
|
||||
self._fd = None
|
||||
|
||||
if self._fd is None:
|
||||
mode = os.O_RDWR if op == fcntl.LOCK_EX else os.O_RDONLY
|
||||
self._fd = os.open(self._file_path, mode)
|
||||
|
Reference in New Issue
Block a user