@@ -427,6 +427,14 @@ def auth_provider(self, value):
427427 See :attr:`.schema_event_refresh_window` for discussion of rationale
428428 """
429429
430+ connect_timeout = 5
431+ """
432+ Timeout, in seconds, for creating new connections.
433+
434+ This timeout covers the entire connection negotiation, including TCP
435+ establishment, options passing, and authentication.
436+ """
437+
430438 sessions = None
431439 control_connection = None
432440 scheduler = None
@@ -465,7 +473,8 @@ def __init__(self,
465473 control_connection_timeout = 2.0 ,
466474 idle_heartbeat_interval = 30 ,
467475 schema_event_refresh_window = 2 ,
468- topology_event_refresh_window = 10 ):
476+ topology_event_refresh_window = 10 ,
477+ connect_timeout = 5 ):
469478 """
470479 Any of the mutable Cluster attributes may be set as keyword arguments
471480 to the constructor.
@@ -518,6 +527,7 @@ def __init__(self,
518527 self .idle_heartbeat_interval = idle_heartbeat_interval
519528 self .schema_event_refresh_window = schema_event_refresh_window
520529 self .topology_event_refresh_window = topology_event_refresh_window
530+ self .connect_timeout = connect_timeout
521531
522532 self ._listeners = set ()
523533 self ._listener_lock = Lock ()
@@ -707,11 +717,11 @@ def connection_factory(self, address, *args, **kwargs):
707717 Intended for internal use only.
708718 """
709719 kwargs = self ._make_connection_kwargs (address , kwargs )
710- return self .connection_class .factory (address , * args , ** kwargs )
720+ return self .connection_class .factory (address , self . connect_timeout , * args , ** kwargs )
711721
712722 def _make_connection_factory (self , host , * args , ** kwargs ):
713723 kwargs = self ._make_connection_kwargs (host .address , kwargs )
714- return partial (self .connection_class .factory , host .address , * args , ** kwargs )
724+ return partial (self .connection_class .factory , host .address , self . connect_timeout , * args , ** kwargs )
715725
716726 def _make_connection_kwargs (self , address , kwargs_dict ):
717727 if self ._auth_provider_callable :
0 commit comments