Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential race condition prevents 'unix.rm' from deleting directory #206

Open
bch0w opened this issue Mar 31, 2024 · 2 comments
Open

potential race condition prevents 'unix.rm' from deleting directory #206

bch0w opened this issue Mar 31, 2024 · 2 comments

Comments

@bch0w
Copy link
Member

bch0w commented Mar 31, 2024

Raised in #205 by @scott314159, there seems to be a race condition during the finalization command of the Pyaflowa preprocessing module where the main job tries to delete the log file directory but returns OSError: [Errno 39] Directory not empty , which traces back from shutil.rmtree.

This seems to be a know issue with shutil.rmtree, see e.g., https://stackoverflow.com/questions/11228079/python-remove-directory-error-file-exists that happens on NFS file systems where file locks are present.

My thinking is that this is a race condition where the file locks cannot be removed before the rm command tries to delete. One potential try is to put a try-except clause in unix.rm that waits a few seconds if it hits this OSError, to give the filesystem some time to remove it's lock.

def rm(path):
"""
Remove files or directories
"""
for name in _iterable(path):
if os.path.isfile(name) or os.path.islink(name):
os.remove(name)
elif os.path.isdir(name):
shutil.rmtree(name)

@scott314159
Copy link

scott314159 commented Apr 1, 2024 via email

@bch0w
Copy link
Member Author

bch0w commented Jun 5, 2024

Hey @scott314159, again, sorry for the long pause in communication here! Yeah the log message removal is intended to reduce file count, as for large-scale problems there may be (hundreds of) thousands of files created which may stress file systems, but I agree there is usually useful information there. The parameter export_log_files is meant to make it a User decision to save these files by copying them to a more permanent location, and is set True by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants