Merge pull request #4440 from pipecat-ai/filipi/daily_send_message_issue
Fixing a race condition when cleaning up the daily transport.
This commit is contained in:
1
changelog/4440.fixed.md
Normal file
1
changelog/4440.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed a race condition in the Daily transport that caused `AttributeError: 'NoneType' object has no attribute 'send_app_message'` when tearing down a pipeline. Both `DailyInputTransport` and `DailyOutputTransport` share the same `DailyTransportClient` and both call `cleanup()`, which was releasing the underlying `CallClient` on the first call — leaving the second caller with a `None` client.
|
||||||
@@ -526,6 +526,7 @@ class DailyTransportClient(EventHandler):
|
|||||||
self._joined = False
|
self._joined = False
|
||||||
self._joined_event = asyncio.Event()
|
self._joined_event = asyncio.Event()
|
||||||
self._leave_counter = 0
|
self._leave_counter = 0
|
||||||
|
self._cleanup_counter = 0
|
||||||
|
|
||||||
self._task_manager: BaseTaskManager | None = None
|
self._task_manager: BaseTaskManager | None = None
|
||||||
|
|
||||||
@@ -741,6 +742,7 @@ class DailyTransportClient(EventHandler):
|
|||||||
Args:
|
Args:
|
||||||
setup: The frame processor setup configuration.
|
setup: The frame processor setup configuration.
|
||||||
"""
|
"""
|
||||||
|
self._cleanup_counter += 1
|
||||||
if self._task_manager:
|
if self._task_manager:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -754,6 +756,12 @@ class DailyTransportClient(EventHandler):
|
|||||||
|
|
||||||
async def cleanup(self):
|
async def cleanup(self):
|
||||||
"""Cleanup client resources and cancel tasks."""
|
"""Cleanup client resources and cancel tasks."""
|
||||||
|
# Decrement cleanup counter. DailyInputTransport and DailyOutputTransport
|
||||||
|
# share this client and both call cleanup(), so only run on the last call.
|
||||||
|
self._cleanup_counter -= 1
|
||||||
|
if self._cleanup_counter > 0:
|
||||||
|
return
|
||||||
|
|
||||||
if self._event_task and self._task_manager:
|
if self._event_task and self._task_manager:
|
||||||
await self._task_manager.cancel_task(self._event_task)
|
await self._task_manager.cancel_task(self._event_task)
|
||||||
self._event_task = None
|
self._event_task = None
|
||||||
|
|||||||
Reference in New Issue
Block a user