From 6f4c6b7c18705a7631573ab025eed7cc4c4308b0 Mon Sep 17 00:00:00 2001 From: Marvin Schenkel Date: Fri, 13 Feb 2026 13:04:47 +0100 Subject: [PATCH] Always cleanup smart fades tmp files (#3143) * Always cleanup smart fades tmp files * Cleanup --- .../controllers/streams/smart_fades/fades.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/music_assistant/controllers/streams/smart_fades/fades.py b/music_assistant/controllers/streams/smart_fades/fades.py index 7c971562..88dc1111 100644 --- a/music_assistant/controllers/streams/smart_fades/fades.py +++ b/music_assistant/controllers/streams/smart_fades/fades.py @@ -75,6 +75,7 @@ class SmartFade(ABC): fadeout_filename = f"/tmp/{shortuuid.random(20)}.pcm" # noqa: S108 async with aiofiles.open(fadeout_filename, "wb") as outfile: await outfile.write(fade_out_part) + args = [ "ffmpeg", "-hide_banner", @@ -132,14 +133,17 @@ class SmartFade(ABC): ) self.logger.log(VERBOSE_LOG_LEVEL, "FFmpeg command args: %s", " ".join(args)) - # Execute the enhanced smart fade with full buffer - _, raw_crossfade_output, stderr = await communicate(args, fade_in_part) - await remove_file(fadeout_filename) - - if raw_crossfade_output: - return raw_crossfade_output - stderr_msg = stderr.decode() if stderr else "(no stderr output)" - raise RuntimeError(f"Smart crossfade failed. FFmpeg stderr: {stderr_msg}") + try: + # Execute the enhanced smart fade with full buffer + _, raw_crossfade_output, stderr = await communicate(args, fade_in_part) + + if raw_crossfade_output: + return raw_crossfade_output + stderr_msg = stderr.decode() if stderr else "(no stderr output)" + raise RuntimeError(f"Smart crossfade failed. FFmpeg stderr: {stderr_msg}") + finally: + # Always cleanup temp file, even if ffmpeg fails + await remove_file(fadeout_filename) def __repr__(self) -> str: """Return string representation of SmartFade showing the filter chain.""" -- 2.34.1