Skip to content

Race condition in storage.py for NestedDirectoryStore writes #272

@jmswaney

Description

@jmswaney

I've encountered a FileExistsError when writing in parallel to a NestedDirectoryStore that says:

FileExistsError: [Errno 17] File exists: '/media/jswaney/Drive/Justin/coregistration/whole_brain_tde/fixed/zarr/4/10'

The error points to the os.makedirs(dir_path) line in __setitem__ for the DirectoryStore class:

dir_path, file_name = os.path.split(file_path)
if os.path.isfile(dir_path):
    raise KeyError(key)
if not os.path.exists(dir_path):
    try:
        os.makedirs(dir_path)  # Error raised here
    except Exception:
        raise KeyError(key)

I was doing the chunk compression with 12 workers, so I think one of them created the subdirectory while another had already checked that it didn't exist. When it got to os.makedirs, it gave the expected error. A quick fix would just be to catch this error, but a better fix might be to just make all the directories for a NestedDirectoryStore ahead of time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions