@@ -2077,6 +2077,7 @@ def on_add(self, host, refresh_nodes=True):
20772077 have_future = False
20782078 add_aborted = False
20792079 futures = set ()
2080+ finalize_add = None
20802081 try :
20812082 self .profile_manager .on_add (host )
20822083 self .control_connection .on_add (host , refresh_nodes )
@@ -2089,59 +2090,61 @@ def on_add(self, host, refresh_nodes=True):
20892090 if distance == HostDistance .IGNORED :
20902091 log .debug ("Not adding connection pool for new host %r because the "
20912092 "load balancing policy has marked it as IGNORED" , host )
2092- self ._finalize_add (host , set_up = False )
2093- return
2094-
2095- futures_lock = Lock ()
2096- futures_results = []
2093+ finalize_add = False
2094+ else :
2095+ futures_lock = Lock ()
2096+ futures_results = []
20972097
2098- def future_completed (future ):
2099- with futures_lock :
2100- futures .discard (future )
2098+ def future_completed (future ):
2099+ with futures_lock :
2100+ futures .discard (future )
21012101
2102- if add_aborted :
2103- return
2102+ if add_aborted :
2103+ return
21042104
2105- try :
2106- futures_results .append (future .result ())
2107- except Exception as exc :
2108- futures_results .append (exc )
2105+ try :
2106+ futures_results .append (future .result ())
2107+ except Exception as exc :
2108+ futures_results .append (exc )
21092109
2110- if futures :
2111- return
2110+ if futures :
2111+ return
21122112
2113- log .debug ('All futures have completed for added host %s' , host )
2113+ log .debug ('All futures have completed for added host %s' , host )
21142114
2115- for exc in [f for f in futures_results if isinstance (f , Exception )]:
2116- log .error ("Unexpected failure while adding node %s, will not mark up:" , host , exc_info = exc )
2117- self ._cleanup_failed_on_add_handling (host )
2118- return
2115+ for exc in [f for f in futures_results if isinstance (f , Exception )]:
2116+ log .error ("Unexpected failure while adding node %s, will not mark up:" , host , exc_info = exc )
2117+ self ._cleanup_failed_on_add_handling (host )
2118+ return
21192119
2120- if not all (futures_results ):
2121- log .warning ("Connection pool could not be created, not marking node %s up" , host )
2122- self ._cleanup_failed_on_add_handling (host )
2123- return
2120+ if not all (futures_results ):
2121+ log .warning ("Connection pool could not be created, not marking node %s up" , host )
2122+ self ._cleanup_failed_on_add_handling (host )
2123+ return
21242124
2125- self ._finalize_add (host )
2125+ self ._finalize_add (host )
21262126
2127- for session in tuple (self .sessions ):
2128- future = session .add_or_renew_pool (host , is_host_addition = True )
2129- if future is not None :
2130- have_future = True
2131- futures .add (future )
2127+ for session in tuple (self .sessions ):
2128+ future = session .add_or_renew_pool (host , is_host_addition = True )
2129+ if future is not None :
2130+ have_future = True
2131+ futures .add (future )
21322132
2133- for future in tuple (futures ):
2134- future .add_done_callback (future_completed )
2133+ for future in tuple (futures ):
2134+ future .add_done_callback (future_completed )
21352135
2136- if not have_future :
2137- self . _finalize_add ( host )
2136+ if not have_future :
2137+ finalize_add = True
21382138 except Exception :
21392139 add_aborted = True
21402140 for future in tuple (futures ):
21412141 future .cancel ()
21422142 self ._cleanup_failed_on_add_handling (host )
21432143 raise
21442144
2145+ if finalize_add is not None :
2146+ self ._finalize_add (host , set_up = finalize_add )
2147+
21452148 def _finalize_add (self , host , set_up = True ):
21462149 try :
21472150 if set_up :
0 commit comments