Race condition in lock file creation could allow concurrent backups
Priority: High Component: backup.py Type: Bug
Description
There's a race condition in the set_backups_lock() function (backup.py:100-131) between checking if the lock file exists and creating it. Two processes could both check for the file, both find it doesn't exist, and both proceed to create backups simultaneously.
Between line 109 and 110, another process could create the lock file, leading to both processes thinking they have the lock.
Proposed Solution
Use atomic file creation with exclusive flags:
try:fd=os.open(lock_file_path,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o644)os.write(fd,str(os.getpid()).encode())os.close(fd)returnTrueexceptFileExistsError:# Lock already exists, read PID and check if process is running...
Impact
High - Could cause data corruption or incomplete backups if two processes run simultaneously.
# Race condition in lock file creation could allow concurrent backups
**Priority:** High
**Component:** backup.py
**Type:** Bug
## Description
There's a race condition in the `set_backups_lock()` function (backup.py:100-131) between checking if the lock file exists and creating it. Two processes could both check for the file, both find it doesn't exist, and both proceed to create backups simultaneously.
## Location
`curateipsum/backup.py:109-112`
## Current Code
```python
if not os.path.exists(lock_file_path):
with open(lock_file_path, "a") as f:
f.write(str(os.getpid()))
return True
```
## Problem
Between line 109 and 110, another process could create the lock file, leading to both processes thinking they have the lock.
## Proposed Solution
Use atomic file creation with exclusive flags:
```python
try:
fd = os.open(lock_file_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
os.write(fd, str(os.getpid()).encode())
os.close(fd)
return True
except FileExistsError:
# Lock already exists, read PID and check if process is running
...
```
## Impact
**High** - Could cause data corruption or incomplete backups if two processes run simultaneously.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Race condition in lock file creation could allow concurrent backups
Priority: High
Component: backup.py
Type: Bug
Description
There's a race condition in the
set_backups_lock()function (backup.py:100-131) between checking if the lock file exists and creating it. Two processes could both check for the file, both find it doesn't exist, and both proceed to create backups simultaneously.Location
curateipsum/backup.py:109-112Current Code
Problem
Between line 109 and 110, another process could create the lock file, leading to both processes thinking they have the lock.
Proposed Solution
Use atomic file creation with exclusive flags:
Impact
High - Could cause data corruption or incomplete backups if two processes run simultaneously.