Fix localfs cache tmp-file leak when key contains a path separator (#69741) - #69960
Open
dwoz wants to merge 1 commit into
Open
Fix localfs cache tmp-file leak when key contains a path separator (#69741)#69960dwoz wants to merge 1 commit into
dwoz wants to merge 1 commit into
Conversation
Since 3008.0 the pillar cache key is `<minion_id>:<pillarenv>`. When
`pillarenv` contains `/` (e.g. `pillar_roots` names like
`someenv/beta`), `localfs.store()` computed an ``outfile`` inside a
subdirectory that did not exist. The atomic rename then failed and the
`tempfile.mkstemp` tmp file was never cleaned up, producing millions of
orphan `tmp*` files under `/var/cache/salt/master/pillar/` and a
repeating traceback in the master log every pillar compile.
Make `localfs.store()`:
* create the parent directory of the target file so keys with `/`
are stored at the natural nested path,
* always remove its `tempfile.mkstemp` scratch file when the write
or rename raises.
Fixes saltstack#69741
twangboy
approved these changes
Aug 5, 2026
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.
Fixes #69741.
Since 3008.0 the pillar cache uses
<minion_id>:<pillarenv>as its cache key (PR #68030). Whenpillarenvcontains/(e.g. hierarchicalpillar_rootsnames likesomeenv/beta),localfs.store()computed anoutfileinside a subdirectory that did not exist. The atomic rename then failed withFileNotFoundErrorand thetempfile.mkstemptmp file was never cleaned up. Reporters saw millions of leakedtmp*files under/var/cache/salt/master/pillar/and a repeating traceback in the master log on every pillar compile.localfs.store()now:/are stored at the natural nested path,tempfile.mkstempscratch file when the write or rename raises.Two regression tests in
tests/pytests/functional/cache/test_localfs.py; both fail against 3008.x tip without this change.