Fix buffered generator hang by ensuring None sentinel delivery (#2566)
authorMaxim Raznatovski <nda.mr43@gmail.com>
Tue, 28 Oct 2025 20:46:54 +0000 (21:46 +0100)
committerGitHub <noreply@github.com>
Tue, 28 Oct 2025 20:46:54 +0000 (21:46 +0100)
music_assistant/helpers/buffered_generator.py

index 42902d122e2101b174b23b1e05e32b06b7dda4c9..523b4883376c174df36acbb23793c81f4471f9d6 100644 (file)
@@ -78,8 +78,10 @@ async def buffered(
             if not generator_consumed:
                 await close_async_generator(generator)
             # Signal end of stream by putting None
-            with contextlib.suppress(asyncio.QueueFull):
-                buffer.put_nowait(None)
+            # We must wait for space in the queue if needed, otherwise the consumer may
+            # hang waiting for data that will never come
+            if not cancelled.is_set():
+                await buffer.put(None)
 
     # Start the producer task
     loop = asyncio.get_running_loop()