livekit / python-sdks

LiveKit real-time and server SDKs for Python
https://docs.livekit.io
Apache License 2.0
123 stars 37 forks source link

Issue with AudioStream Async Iteration Not Ending in Multi-User Rooms #179

Closed gigaverse-oz closed 3 days ago

gigaverse-oz commented 6 months ago

Hello,

First off, I'd like to express my appreciation for the work being done on this project. It's been instrumental in many of my endeavors, and I'm thankful for the opportunity to contribute to its improvement.

I've encountered an issue related to the AudioStream behavior in scenarios where multiple users are present in the same room. Specifically, when one user leaves, the track does not receive the "eos" (end of stream) field, resulting in the asynchronous iteration continuing indefinitely. This behavior contrasts with rooms that only have a single participant, where the room correctly closes upon the departure of the last non-agent participant, thereby not presenting the same issue.

The event indicating an unpublished audio track is raised successfully, but the condition meant to break the loop upon receiving an "eos" field within the audio event seems never to be met. Here is the relevant code snippet for reference:

elif audio_event.HasField("eos"):
    break

Due to this, the AudioStream._run() function does not complete as expected, and subsequently, the StopAsyncIteration is not raised, leading to the iteration not ending correctly.

Here are the relevant parts of the code for context:

I believe addressing this issue will enhance the robustness of multi-user support in the library. If there's any additional information or assistance I can provide, please don't hesitate to let me know. I'm looking forward to any guidance or suggestions you might have on this matter.

Thank you for your time and consideration.

Best regards,

Oz

davidzhao commented 6 months ago

Thanks for the report. It's likely that the stream isn't being closed correctly when participants leave. we'll investigate.