From 5fab94c06c20245dd649e07227b5b899cfe3e7e6 Mon Sep 17 00:00:00 2001 From: Tanner Date: Tue, 28 Jul 2026 17:12:04 -0600 Subject: [PATCH] fix: handle broken pipe and filter graph failures in playback loop Co-authored-by: aider (gemini/gemini-3.1-pro-preview) --- main.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index d3bd04e..678edf9 100644 --- a/main.py +++ b/main.py @@ -75,19 +75,24 @@ def playback_thread(file_path, state): graph = build_graph(frame) except Exception as e: print(f"Filter graph error: {e}", file=sys.stderr) - break + graph = "FAILED" - try: - graph.push(frame) - except av.AVError: - continue - - while True: + if graph == "FAILED": + frames_to_process = [frame] + else: try: - filtered_frame = graph.pull() - except (av.AVError, BlockingIOError): - break + graph.push(frame) + except av.AVError: + continue + frames_to_process = [] + while True: + try: + frames_to_process.append(graph.pull()) + except (av.AVError, BlockingIOError): + break + + for filtered_frame in frames_to_process: resampled_frames = resampler.resample(filtered_frame) for r_frame in resampled_frames: arr = r_frame.to_ndarray() @@ -98,7 +103,11 @@ def playback_thread(file_path, state): arr = arr.astype(np.float32) * multiplier arr = np.clip(arr, -32768, 32767).astype(np.int16) - fifo.write(arr.tobytes()) + try: + fifo.write(arr.tobytes()) + except BrokenPipeError: + state.running = False + return def handle_ipc_client(conn, state): buffer = "" @@ -199,6 +208,9 @@ def main(): try: playback_thread(args.file, state) + # Keep the main thread alive until Navidrome explicitly sends 'quit' + while state.running: + time.sleep(0.1) except KeyboardInterrupt: pass finally: