Fixed an issue where the pipeline could freeze.

This commit is contained in:
Filipi Fuchter
2025-09-02 13:58:41 -03:00
parent 64486ef50b
commit dea7c22020
3 changed files with 26 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
"""Deepgram speech-to-text service implementation."""
import asyncio
from typing import AsyncGenerator, Dict, Optional
from loguru import logger
@@ -237,7 +238,16 @@ class DeepgramSTTService(STTService):
async def _disconnect(self):
if self._connection.is_connected:
logger.debug("Disconnecting from Deepgram")
await self._connection.finish()
result = await self._connection.finish()
# Deepgram swallows asyncio.CancelledError internally and returns False instead.
# This prevents proper cancellation propagation: tasks awaiting on queue.get()
# would remain stuck if we didnt normalize this back into a CancelledError.
# GH issue: https://github.com/deepgram/deepgram-python-sdk/issues/570
if not result:
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):
"""Start TTFB and processing metrics collection."""