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

siibra cache is not thread-safe #489

Open
ch-schiffer opened this issue Oct 12, 2023 · 2 comments
Open

siibra cache is not thread-safe #489

ch-schiffer opened this issue Oct 12, 2023 · 2 comments
Assignees
Labels
bug Something isn't working caching&persistence Issues related to storing siibra objects - caching persistence and serialization.

Comments

@ch-schiffer
Copy link
Contributor

I just encountered an error while running parallel siibra calls from many different processes (through snakemake):

[Errno 2] No such file or directory: '/home/cschiffer/.cache/siibra.retrieval/56458555fc977a3234ba8523b554bc2eced8d2594e2efe52462e52e23638de6b_temp.lock'
  File "/mnt/ssd1/code/bigbrain_dl_feature_analysis/snakemake/bigbrain_features/Snakefile", line 172, in __rule_cortical_layer_meshes
  File "/mnt/ssd1/code/siibra-python/siibra/__init__.py", line 26, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/core/__init__.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/core/atlas.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/core/space.py", line 20, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/locations/__init__.py", line 17, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/locations/point.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/locations/boundingbox.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/locations/pointset.py", line 18, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/__init__.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/repositories.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/requests.py", line 16, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/cache.py", line 136, in <module>
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/cache.py", line 66, in instance
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/cache.py", line 82, in run_maintenance
  File "/mnt/ssd1/code/siibra-python/siibra/retrieval/cache.py", line 82, in <listcomp>
  File "/home/cschiffer/mamba/envs/atlas/lib/python3.11/concurrent/futures/thread.py", line 58, in runRuleException:

The same error occurred for multiple parallel processes at the same time. This makes me assume that the file-based cache that siibra uses internally is probably not thread-safe. I had a quick look at the code of the cache, in particular the run_maintenance function. This function seems to delete some previously identified files from the cache. However, there is no check to handle the case where another process deletes a file after it was found in the folder. As I see it, this is indeed not safe to use from multiple processes/threads.
Checking whether a file still exists before deleting it, or putting a lock around cache modifications in general could solve this issue (although the latter probably would have some performance implications).

@ch-schiffer ch-schiffer added bug Something isn't working caching&persistence Issues related to storing siibra objects - caching persistence and serialization. labels Oct 12, 2023
@ch-schiffer
Copy link
Contributor Author

Hey @AhmetNSimsek , just wanted to check what the status here is. #496 was not merged as far as I understood, so was anything implemented to address thread safety? My ancient siibra version (0.4a77) is not thread-safe, but before (finally) going through the effort of updating, I wanted to be sure that it is worth it wrt. thread safety.

@ch-schiffer
Copy link
Contributor Author

For future reference, setting export SKIP_CACHEINIT_MAINTENANCE=True to disable the cache maintenance altogether works as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working caching&persistence Issues related to storing siibra objects - caching persistence and serialization.
Projects
None yet
Development

No branches or pull requests

3 participants