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

Fix directory creation race condition in Folder and SandboxFolder #4912

Commits on May 5, 2021

  1. Fix directory creation race condition in Folder and SandboxFolder

    The `Folder` and `SandboxFolder` classes of `aiida.common.folders` used
    the following paradigm to create the required folders:
    
        if not os.path.exists(filepath):
            os.makedirs(filepath)
    
    However, this is susceptible to a race condition. If two processes call
    the same piece of code almost at the same time, they may both evaluate
    the conditional to be True if the filepath does not yet exist, but one
    of the two will actually get to the creation first, causing the second
    process to except with a `FileExistsError`.
    
    The solution is to replace it with `os.makedirs(filepath, exist_ok=True)`
    which will swallow the exception if the path already exists.
    sphuber committed May 5, 2021
    Configuration menu
    Copy the full SHA
    74c581e View commit details
    Browse the repository at this point in the history