WebsocketService: avoid reconnection on shutdown

This commit is contained in:
Aleix Conchillo Flaqué
2025-12-05 08:50:03 -08:00
parent fed6a8b669
commit 48422dd442
2 changed files with 7 additions and 1 deletions

2
changelog/3185.fixed.md Normal file
View File

@@ -0,0 +1,2 @@
- Fixed an issue that caused `WebsocketService` instances to attempt
reconnection during shutdown.

View File

@@ -12,7 +12,7 @@ from typing import Awaitable, Callable, Optional
import websockets
from loguru import logger
from websockets.exceptions import ConnectionClosedOK
from websockets.exceptions import ConnectionClosedError, ConnectionClosedOK
from websockets.protocol import State
from pipecat.frames.frames import ErrorFrame
@@ -137,6 +137,10 @@ class WebsocketService(ABC):
# Normal closure, don't retry
logger.debug(f"{self} connection closed normally: {e}")
break
except ConnectionClosedError as e:
# Error closure, don't retry
logger.warning(f"{self} connection closed, but with an error: {e}")
break
except Exception as e:
message = f"{self} error receiving messages: {e}"
logger.error(message)