Bug Description
I was reading the livekit project while i came to this issue
What is the issue?
There is a task leak when closing an agent session.
When a voice session starts, it runs two background tasks: one for audio and one for video. When the session is closed, the code cleanly stops the audio task but completely forgets to stop the video task.
If a session is closed early (before it fully initializes), the video task is left running in the background forever. Over time, this leaks memory as more sessions open and close.
How I fixed it
I added a simple check to stop and clean up the video task at the end of the session, exactly the same way the audio task is stopped:
if self._forward_video_atask is not None:
await utils.aio.cancel_and_wait(self._forward_video_atask)
github pull request - #6318
Expected Behavior
Expected Behavior
When an agent session is closed, all background tasks (both audio and video stream tasks) should be fully stopped and cleaned up, leaving no orphaned tasks running in the background.
Reproduction Steps
1.
2.
3.
...
- Sample code snippet, or a GitHub Gist link -
Operating System
Debian 13
Models Used
No response
Package Versions
Session/Room/Call IDs
No response
Proposed Solution
Additional Context
No response
Screenshots and Recordings
No response
Bug Description
I was reading the livekit project while i came to this issue
What is the issue?
There is a task leak when closing an agent session.
When a voice session starts, it runs two background tasks: one for audio and one for video. When the session is closed, the code cleanly stops the audio task but completely forgets to stop the video task.
If a session is closed early (before it fully initializes), the video task is left running in the background forever. Over time, this leaks memory as more sessions open and close.
How I fixed it
I added a simple check to stop and clean up the video task at the end of the session, exactly the same way the audio task is stopped:
github pull request - #6318
Expected Behavior
Expected Behavior
When an agent session is closed, all background tasks (both audio and video stream tasks) should be fully stopped and cleaned up, leaving no orphaned tasks running in the background.
Reproduction Steps
Operating System
Debian 13
Models Used
No response
Package Versions
Session/Room/Call IDs
No response
Proposed Solution
Additional Context
No response
Screenshots and Recordings
No response