Skip to content

Ensure cache directory exists when attempting to use it - #274

Open
pR0Ps wants to merge 1 commit into
spl0k:masterfrom
pR0Ps:bugfix/missing-cache-folder
Open

Ensure cache directory exists when attempting to use it#274
pR0Ps wants to merge 1 commit into
spl0k:masterfrom
pR0Ps:bugfix/missing-cache-folder

Conversation

@pR0Ps

@pR0Ps pR0Ps commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Even though the cache directory is created when the object is initialized, it's possible for it to be deleted while the program is running, leading to failures to create the temporary files.

In my specific case, I have the cache set up to use a subdirectory of /tmp, which is occasionally cleaned up by the operating system. This leads to errors like the following when attempting to cache transcodes or extract album art:

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/werkzeug/wsgi.py", line 256, in __next__
    return self._next()
  File "/usr/lib/python3.12/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
    for item in iterable:
  File "/usr/lib/python3.12/site-packages/supysonic/cache.py", line 183, in set_generated
    with self.set_fileobj(key) as f:
  File "/usr/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.12/site-packages/supysonic/cache.py", line 144, in set_fileobj
    f = tempfile.NamedTemporaryFile(
  File "/usr/lib/python3.12/tempfile.py", line 582, in NamedTemporaryFile
    file = _io.open(dir, mode, buffering=buffering,
  File "/usr/lib/python3.12/tempfile.py", line 579, in opener
    fd, name = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "/usr/lib/python3.12/tempfile.py", line 256, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/supysonic/transcodes/tmp8dnfpyvr.part'

Even though the cache directory is created when the object is
initialized, it's possible for it to be deleted while the program is
running, leading to failures to create the temporary files.
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.56%. Comparing base (1f3471c) to head (ea92180).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #274   +/-   ##
=======================================
  Coverage   95.56%   95.56%           
=======================================
  Files          54       54           
  Lines        4310     4311    +1     
=======================================
+ Hits         4119     4120    +1     
  Misses        191      191           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@spl0k

spl0k commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Hello!

Since a transcode can take some time, isn't there a window where a cleanup can happen between the temporary file creation and its rename on line 154? That would most likely raise the same kind of error there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants