Repository navigation
Fix race in s3fs _write_buckets_cache_file cache removal (#69529) - #69670
Merged
Merged
Conversation
Under overlapping S3 fileserver cache refreshes, _write_buckets_cache_file could race between the os.path.isfile guard and the os.remove call: a concurrent invocation may have already deleted the stale cache file, so the second call raised an unhandled FileNotFoundError. The exception propagated through the async handler, polluted the event bus with a stringified traceback, and left the master unresponsive. Replace the TOCTOU pattern with an unconditional os.remove wrapped in try/except FileNotFoundError, so concurrent refreshes now no-op on the already-removed file instead of aborting the write. Fixes saltstack#69529
twangboy
approved these changes
Jul 9, 2026
This branch was previously 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.
What does this PR do?
Fixes a race in
salt.fileserver.s3fs._write_buckets_cache_filewhere twoconcurrent cache refreshes could raise an unhandled
FileNotFoundErrorwhen the second call reached
os.removeafter the first call had alreadyremoved the stale cache file. The removal is now tolerant of the file
being missing.
What issues does this PR fix or reference?
Fixes #69529
Previous Behavior
Under the default
s3_cache_expire: 30ands3_sync_on_update: True,overlapping S3 fileserver cache refreshes hit the TOCTOU between the
os.path.isfile(cache_file)guard and theos.remove(cache_file)call.The unhandled
FileNotFoundErrorpropagated up through the async handler,polluting the event bus with a stringified traceback ("
Event iteration failed with exception: 'str' object has no attribute 'items'") andleaving the master unresponsive until it was restarted.
New Behavior
_write_buckets_cache_fileunconditionally attempts to remove the stalecache file inside a
try/except FileNotFoundError: pass. Concurrentrefreshes are now idempotent — the second call quietly no-ops on the
already-removed file and rewrites the cache atomically.
A regression test in
tests/pytests/unit/fileserver/test_s3fs.py(
test_write_buckets_cache_file_race_condition) patchesos.removetosimulate the race and asserts that the write completes and the new
metadata round-trips.
Merge requirements satisfied?
changelog/69529.fixed.md)Commits signed with GPG?
Yes
Notes
salt/fileserver/s3fs.pywas purged from3007.xonwards (commitdc526dc2b17"Initial purge of community extensions") in favor ofsaltstack/saltext-s3fs. This PR therefore targets3006.xonly — theoldest and only supported branch that still ships the affected file. A
follow-up PR against the extension repository will be needed to carry the
same fix forward if
saltext-s3fsstill has this pattern.