Skip to content

Commit

Permalink
Fixed issue with duplicated sio handlers (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonKirill authored Dec 5, 2024
1 parent e20db61 commit 20e3bd7
Showing 1 changed file with 8 additions and 7 deletions.
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

0 comments on commit 20e3bd7

Please sign in to comment.