Repository navigation
Fix FileNotFoundError when clear_cache() races with separate_files=True - #400
Open
lode-braced wants to merge 1 commit into
Open
lode-braced wants to merge 1 commit into
lode-braced wants to merge 1 commit into
Conversation
… files Two concurrent clear_cache() calls with separate_files=True could both list the same cache file; the slower caller then failed with FileNotFoundError. Treat a file that is already gone as cleared and continue with the remaining files. Closes python-cachier#399
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #399
Problem
With the pickle backend and
separate_files=True,_PickleCore._clear_all_cache_files()lists the cache directory and then removes each matching file. If twoclear_cache()calls run concurrently (same wrapper from two threads, or separate wrappers/processes sharing acache_dir), both can list the same file. One removes it; the other'sos.remove()then raisesFileNotFoundError, aborting that clear before it processes the remaining files.The existing retry loop only handles
PermissionError(Windows file locking), so the missing-file case propagates.Fix
Treat
FileNotFoundErrorfrom the per-fileos.remove()as "already cleared" and continue with the next file. The handler wraps only the individual deletion.PermissionErrorretry behavior and propagation of other errors are unchanged. No new locking is introduced.This does not address in-flight computations re-creating entries after a clear; that is a separate invalidation concern.
Tests
Adds
test_concurrent_clear_cache_separate_files, parametrized for a shared wrapper and for separate wrappers on the same directory. It uses real cache files and real deletions, and coordinates scheduling deterministically: both callers list the directory before either deletes, and the second deletion of each file is attempted only after the first completes. It asserts that both clears succeed, that all matching files are removed, and that unrelated files are untouched. The test fails on the currentmasterand passes with this change.