Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with duplicated sio handlers #113

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions services/klatchat_observer/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ def __init__(
Recipients.NEON: self.__handle_neon_recipient,
Recipients.CHATBOT_CONTROLLER: self.__handle_chatbot_recipient,
}
self._sio: socketio.Client = None
self.sio_url = config["SIO_URL"]

self._sio: socketio.Client = socketio.Client()
self.sio_connected = False
self.register_sio_handlers()

self.server_url = self.sio_url
self._klat_session_token = None
self.klat_auth_credentials = config.get("KLAT_AUTH_CREDENTIALS", {})
self.default_persona_llms = dict()

self.sio_connected = False
self.default_persona_llms = dict()

self.register_consumer(
name="neon_response",
Expand Down Expand Up @@ -334,14 +337,12 @@ def connect_sio(self):
"""
Method for establishing connection with Socket IO server
"""
self._sio = socketio.Client()
self._sio.connect(
url=self.sio_url,
namespaces=["/"],
retry=True,
headers={"session": self._klat_session_token},
)
self.register_sio_handlers()

@property
def sio(self):
Expand All @@ -351,7 +352,7 @@ def sio(self):

:return: connected async socket io instance
"""
if not (self._sio and self.sio_connected):
if not self.sio_connected:
try:
# Assuming that Socket IO is connected unless Exception is raised during the connection
# This is done to prevent parallel invocation of this method from consumers
Expand Down Expand Up @@ -844,7 +845,7 @@ def _login_to_klat_server(self):
)
if response.ok:
self._klat_session_token = response.json()["token"]
self.sio.disconnect()
self._sio.disconnect()
self.sio_connected = False
else:
LOG.error(
Expand Down
Loading