From 48422dd442b4e43357f16321d4d711fe5aeee646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 5 Dec 2025 08:50:03 -0800 Subject: [PATCH] WebsocketService: avoid reconnection on shutdown --- changelog/3185.fixed.md | 2 ++ src/pipecat/services/websocket_service.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog/3185.fixed.md diff --git a/changelog/3185.fixed.md b/changelog/3185.fixed.md new file mode 100644 index 000000000..2dcdd4728 --- /dev/null +++ b/changelog/3185.fixed.md @@ -0,0 +1,2 @@ +- Fixed an issue that caused `WebsocketService` instances to attempt + reconnection during shutdown. diff --git a/src/pipecat/services/websocket_service.py b/src/pipecat/services/websocket_service.py index d19e6ad4d..1179c4c03 100644 --- a/src/pipecat/services/websocket_service.py +++ b/src/pipecat/services/websocket_service.py @@ -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)