DeepgramSTTService: remove raising CancelledError

This commit is contained in:
Aleix Conchillo Flaqué
2025-09-03 09:35:38 -07:00
parent c71cec04d3
commit b52296450c

View File

@@ -238,16 +238,15 @@ class DeepgramSTTService(STTService):
async def _disconnect(self): async def _disconnect(self):
if self._connection.is_connected: if self._connection.is_connected:
logger.debug("Disconnecting from Deepgram") logger.debug("Disconnecting from Deepgram")
result = await self._connection.finish() # Deepgram swallows asyncio.CancelledError internally which prevents
# Deepgram swallows asyncio.CancelledError internally and returns False instead. # proper cancellation propagation. This issue was found with
# This prevents proper cancellation propagation: tasks awaiting on queue.get() # parallel pipelines where `CancelFrame` was not awaited for to
# would remain stuck if we didnt normalize this back into a CancelledError. # finish in all branches and it was pushed downstream reaching the
# end of the pipeline, which caused `cleanup()` to be called while
# Deepgram disconnection was still finishing and therefore
# preventing the task cancellation that occurs during `cleanup()`.
# GH issue: https://github.com/deepgram/deepgram-python-sdk/issues/570 # GH issue: https://github.com/deepgram/deepgram-python-sdk/issues/570
if not result: await self._connection.finish()
logger.warning(f"{self}: Deepgram connection failed to disconnect, forcing cancel.")
raise asyncio.CancelledError(
f"{self}: Deepgram connection cancelled during disconnect"
)
async def start_metrics(self): async def start_metrics(self):
"""Start TTFB and processing metrics collection.""" """Start TTFB and processing metrics collection."""