@@ -426,6 +426,14 @@ def auth_provider(self, value):
426426 See :attr:`.schema_event_refresh_window` for discussion of rationale
427427 """
428428
429+ connect_timeout = 5
430+ """
431+ Timeout, in seconds, for creating new connections.
432+
433+ This timeout covers the entire connection negotiation, including TCP
434+ establishment, options passing, and authentication.
435+ """
436+
429437 sessions = None
430438 control_connection = None
431439 scheduler = None
@@ -464,7 +472,8 @@ def __init__(self,
464472 control_connection_timeout = 2.0 ,
465473 idle_heartbeat_interval = 30 ,
466474 schema_event_refresh_window = 2 ,
467- topology_event_refresh_window = 10 ):
475+ topology_event_refresh_window = 10 ,
476+ connect_timeout = 5 ):
468477 """
469478 Any of the mutable Cluster attributes may be set as keyword arguments
470479 to the constructor.
@@ -517,6 +526,7 @@ def __init__(self,
517526 self .idle_heartbeat_interval = idle_heartbeat_interval
518527 self .schema_event_refresh_window = schema_event_refresh_window
519528 self .topology_event_refresh_window = topology_event_refresh_window
529+ self .connect_timeout = connect_timeout
520530
521531 self ._listeners = set ()
522532 self ._listener_lock = Lock ()
@@ -706,11 +716,11 @@ def connection_factory(self, address, *args, **kwargs):
706716 Intended for internal use only.
707717 """
708718 kwargs = self ._make_connection_kwargs (address , kwargs )
709- return self .connection_class .factory (address , * args , ** kwargs )
719+ return self .connection_class .factory (address , self . connect_timeout , * args , ** kwargs )
710720
711721 def _make_connection_factory (self , host , * args , ** kwargs ):
712722 kwargs = self ._make_connection_kwargs (host .address , kwargs )
713- return partial (self .connection_class .factory , host .address , * args , ** kwargs )
723+ return partial (self .connection_class .factory , host .address , self . connect_timeout , * args , ** kwargs )
714724
715725 def _make_connection_kwargs (self , address , kwargs_dict ):
716726 if self ._auth_provider_callable :
0 commit comments