Skip to content

Fix localfs cache tmp-file leak when key contains a path separator (#69741) - #69960

Open
dwoz wants to merge 1 commit into
saltstack:3008.xfrom
dwoz:dwoz/fix/69741-pillarenv-slash-tmp-leak
Open

Fix localfs cache tmp-file leak when key contains a path separator (#69741)#69960
dwoz wants to merge 1 commit into
saltstack:3008.xfrom
dwoz:dwoz/fix/69741-pillarenv-slash-tmp-leak

Conversation

@dwoz

@dwoz dwoz commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #69741.

Since 3008.0 the pillar cache uses <minion_id>:<pillarenv> as its cache key (PR #68030). When pillarenv contains / (e.g. hierarchical pillar_roots names like someenv/beta), localfs.store() computed an outfile inside a subdirectory that did not exist. The atomic rename then failed with FileNotFoundError and the tempfile.mkstemp tmp file was never cleaned up. Reporters saw millions of leaked tmp* files under /var/cache/salt/master/pillar/ and a repeating traceback in the master log on every pillar compile.

localfs.store() now:

  • creates the parent directory of the target file so keys with / are stored at the natural nested path,
  • always removes its tempfile.mkstemp scratch 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.

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 twangboy linked an issue Aug 5, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: pillarenv containing "/" leaks temp files since 3008.0

2 participants