Skip to content

Commit

Permalink
Fix race between exists() and mkdir()
Browse files Browse the repository at this point in the history
The code previously could fail if another process made
a directory with the same name after we called os.path.exists()
but before mkdir().
  • Loading branch information
benmwebb committed Feb 20, 2020
1 parent b3f6c89 commit 4bc4a76
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/saliweb/frontend/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def is_job_in_db():

job_dir = _get_job_directory(job_name)
if not os.path.exists(job_dir) and not is_job_in_db():
os.mkdir(job_dir)
try:
os.mkdir(job_dir)
except FileExistsError:
# Directory may have been made between exists() check and mkdir()
return None
if not is_job_in_db(): # avoid race condition
return job_dir

Expand Down

0 comments on commit 4bc4a76

Please sign in to comment.