Merge pull request #2411 from pipecat-ai/mb/fix-websocket-service-retry
fix: WebsocketService retry logic incorrectly handling ConnectionClos…
This commit is contained in:
@@ -5,7 +5,7 @@ All notable changes to **Pipecat** will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## Unreleased
|
## [Unreleased]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@@ -48,6 +48,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed an issue that would cause system frames to not be processed with higher
|
- Fixed an issue that would cause system frames to not be processed with higher
|
||||||
priority than other frames. This could cause slower interruption times.
|
priority than other frames. This could cause slower interruption times.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an issue where retrying a websocket connection error would result in an
|
||||||
|
error.
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
|
|
||||||
- Added foundational example `15a-switch-languages.py` to release evals. It is
|
- Added foundational example `15a-switch-languages.py` to release evals. It is
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from typing import Awaitable, Callable, Optional
|
|||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from websockets.exceptions import ConnectionClosedOK
|
||||||
from websockets.protocol import State
|
from websockets.protocol import State
|
||||||
|
|
||||||
from pipecat.frames.frames import ErrorFrame
|
from pipecat.frames.frames import ErrorFrame
|
||||||
@@ -82,12 +83,10 @@ class WebsocketService(ABC):
|
|||||||
try:
|
try:
|
||||||
await self._receive_messages()
|
await self._receive_messages()
|
||||||
retry_count = 0 # Reset counter on successful message receive
|
retry_count = 0 # Reset counter on successful message receive
|
||||||
if self._websocket and self._websocket.state is State.CLOSED:
|
except ConnectionClosedOK as e:
|
||||||
raise websockets.ConnectionClosedOK(
|
# Normal closure, don't retry
|
||||||
self._websocket.close_rcvd,
|
logger.debug(f"{self} connection closed normally: {e}")
|
||||||
self._websocket.close_sent,
|
break
|
||||||
self._websocket.close_rcvd_then_sent,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
message = f"{self} error receiving messages: {e}"
|
message = f"{self} error receiving messages: {e}"
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user