1313from momento .auth import CredentialProvider
1414from momento .config import Configuration , TopicConfiguration
1515from momento .config .transport .transport_strategy import StaticGrpcConfiguration
16+ from momento .errors .exceptions import ConnectionException
1617from momento .internal ._utilities import momento_version
1718from momento .internal ._utilities ._channel_credentials import (
1819 channel_credentials_from_root_certs_or_default ,
2122 grpc_control_channel_options_from_grpc_config ,
2223 grpc_data_channel_options_from_grpc_config ,
2324)
25+ from momento .internal .services import Service
2426from momento .internal .synchronous ._add_header_client_interceptor import (
2527 AddHeaderClientInterceptor ,
2628 AddHeaderStreamingClientInterceptor ,
@@ -97,7 +99,11 @@ def on_timeout() -> None:
9799 )
98100 # the subscription is no longer needed; it was only meant to watch if we could connect eagerly
99101 self ._secure_channel .unsubscribe (on_state_change )
100- raise RuntimeError ("Failed to connect to Momento's server within given eager connection timeout" )
102+ self ._secure_channel .close ()
103+ raise ConnectionException (
104+ message = "Failed to connect to Momento's server within given eager connection timeout" ,
105+ service = Service .CACHE ,
106+ )
101107
102108 """
103109 A callback that is triggered whenever a connection's state changes. We explicitly subscribe to
@@ -122,7 +128,7 @@ def on_state_change(state: grpc.ChannelConnectivity) -> None:
122128 elif state == connecting :
123129 self ._logger .debug ("State transitioned to CONNECTING; waiting to get READY" )
124130 else :
125- self ._logger .warn (f"Unexpected connection state: { state } . while trying to eagerly connect" )
131+ self ._logger .warn (f"Unexpected connection state while trying to eagerly connect: { state } " )
126132 # we could not connect within the timeout and we no longer need this subscription
127133 self ._secure_channel .unsubscribe (on_state_change )
128134 connection_event .set ()
0 commit comments