Merge pull request #4347 from pipecat-ai/mb/deepgram-stt-keepalive-unbound
This commit is contained in:
1
changelog/4347.fixed.md
Normal file
1
changelog/4347.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed a crash in `DeepgramSTTService` when an `STTUpdateSettingsFrame` arrived before the WebSocket handshake completed (for example, when pushing an update upstream on `StartFrame`). The settings-triggered reconnect cancelled the in-flight connection task before its keepalive task was created, causing an `UnboundLocalError: cannot access local variable 'keepalive_task'` in the handler's `finally` block.
|
||||||
@@ -621,6 +621,7 @@ class DeepgramSTTService(STTService):
|
|||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
connect_kwargs = self._build_connect_kwargs()
|
connect_kwargs = self._build_connect_kwargs()
|
||||||
|
keepalive_task = None
|
||||||
try:
|
try:
|
||||||
async with self._client.listen.v1.connect(**connect_kwargs) as connection:
|
async with self._client.listen.v1.connect(**connect_kwargs) as connection:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
@@ -639,7 +640,8 @@ class DeepgramSTTService(STTService):
|
|||||||
finally:
|
finally:
|
||||||
self._connection_ready.clear()
|
self._connection_ready.clear()
|
||||||
self._connection = None
|
self._connection = None
|
||||||
await self.cancel_task(keepalive_task)
|
if keepalive_task:
|
||||||
|
await self.cancel_task(keepalive_task)
|
||||||
|
|
||||||
async def _keepalive_handler(self):
|
async def _keepalive_handler(self):
|
||||||
"""Periodically send KeepAlive frames to prevent server-side timeout.
|
"""Periodically send KeepAlive frames to prevent server-side timeout.
|
||||||
|
|||||||
Reference in New Issue
Block a user