@@ -799,23 +799,23 @@ class HappysocksClient:
799799 """
800800 HEADER_AUTH_TOKEN = "x-auth-token"
801801 HEADER_BZM_SESSION = "x-bzm-session"
802- REQUEST_TIMEOUT = 10
803802
804803 def __init__ (self , happysocks_address : str , session_id : str , session_token : str , verbose_logging = False ,
805- verify_ssl = True ) -> None :
804+ verify_ssl = True , request_timeout = 10 , connect_timeout = 7 ) -> None :
806805 super ().__init__ ()
807806 self ._log = logging .getLogger (self .__class__ .__name__ )
808807 parsed_url = urlparse (happysocks_address )
809808 self ._session_token = session_token
810809 self ._session_id = session_id
811810 self ._happysocks_address = f"{ parsed_url .scheme } ://{ parsed_url .netloc } "
812811 self ._socketio_path = f"{ parsed_url .path .rstrip ('/' )} /api-ws"
812+ self ._connect_timeout = connect_timeout
813813 # socketio logging is too verbose by default
814814 socketio_logger = logging .getLogger ("SocketIO" ) if verbose_logging else False
815815 http_session = requests .Session ()
816816 http_session .verify = verify_ssl
817817 self ._sio = socketio .Client (http_session = http_session , logger = socketio_logger , engineio_logger = socketio_logger ,
818- request_timeout = HappysocksClient . REQUEST_TIMEOUT )
818+ request_timeout = request_timeout )
819819 self ._engine_namespace = HappysocksEngineNamespace ()
820820 self ._sio .register_namespace (self ._engine_namespace )
821821
@@ -826,11 +826,17 @@ def connect(self):
826826 }
827827 full_address = f"{ self ._happysocks_address } { self ._socketio_path } "
828828 self ._log .info (f"Connecting to happysocks server { full_address } " )
829+ start_time = time .time ()
829830 try :
830831 self ._sio .connect (self ._happysocks_address , namespaces = [HappysocksEngineNamespace .NAMESPACE ],
831- transports = ['websocket' ], socketio_path = self ._socketio_path , headers = headers )
832+ transports = ['websocket' ], socketio_path = self ._socketio_path , headers = headers ,
833+ wait_timeout = self ._connect_timeout )
834+ end_time = time .time ()
835+ self ._log .info (f"Connected to happysocks server ({ round (end_time - start_time , 2 )} s)" )
832836 except ConnectionError as e :
833- raise TaurusNetworkError (f"Failed to connect to happysocks server { full_address } " ) from e
837+ end_time = time .time ()
838+ raise TaurusNetworkError (
839+ f"Failed to connect to happysocks server { full_address } ({ round (end_time - start_time , 2 )} s)" ) from e
834840
835841 def connected (self ):
836842 """
@@ -846,6 +852,7 @@ def disconnect(self):
846852 if self ._sio ._reconnect_abort :
847853 self ._sio ._reconnect_abort .set ()
848854 self ._sio .disconnect ()
855+ self ._log .info ("Disconnected from happysocks server" )
849856
850857 def send_engine_metrics (self , metrics_batch : List [dict ]):
851858 self ._log .debug (f"Sending { len (metrics_batch )} metrics items to happysocks" )
0 commit comments