@@ -1991,7 +1991,7 @@ def on_up(self, host):
1991
1991
futures_results = []
1992
1992
callback = partial (self ._on_up_future_completed , host , futures , futures_results , futures_lock )
1993
1993
for session in tuple (self .sessions ):
1994
- future = session .add_or_renew_pool (host , is_host_addition = False )
1994
+ future = session .add_or_renew_pool (host , is_host_addition = False , require_previous_shutdown_or_none = False )
1995
1995
if future is not None :
1996
1996
have_future = True
1997
1997
future .add_done_callback (callback )
@@ -2130,7 +2130,7 @@ def future_completed(future):
2130
2130
2131
2131
have_future = False
2132
2132
for session in tuple (self .sessions ):
2133
- future = session .add_or_renew_pool (host , is_host_addition = True )
2133
+ future = session .add_or_renew_pool (host , is_host_addition = True , require_previous_shutdown_or_none = False )
2134
2134
if future is not None :
2135
2135
have_future = True
2136
2136
futures .add (future )
@@ -2661,7 +2661,7 @@ def __init__(self, cluster, hosts, keyspace=None):
2661
2661
# create connection pools in parallel
2662
2662
self ._initial_connect_futures = set ()
2663
2663
for host in hosts :
2664
- future = self .add_or_renew_pool (host , is_host_addition = False )
2664
+ future = self .add_or_renew_pool (host , is_host_addition = False , require_previous_shutdown_or_none = False )
2665
2665
if future :
2666
2666
self ._initial_connect_futures .add (future )
2667
2667
@@ -3284,7 +3284,7 @@ def __del__(self):
3284
3284
# when cluster.shutdown() is called explicitly.
3285
3285
pass
3286
3286
3287
- def add_or_renew_pool (self , host , is_host_addition ):
3287
+ def add_or_renew_pool (self , host , is_host_addition , require_previous_shutdown_or_none ):
3288
3288
"""
3289
3289
For internal use only.
3290
3290
"""
@@ -3332,7 +3332,11 @@ def callback(pool, errors):
3332
3332
self ._lock .acquire ()
3333
3333
return False
3334
3334
self ._lock .acquire ()
3335
- self ._pools [host ] = new_pool
3335
+ if require_previous_shutdown_or_none and (previous and not previous .is_shutdown ):
3336
+ new_pool .shutdown ()
3337
+ return True
3338
+ else :
3339
+ self ._pools [host ] = new_pool
3336
3340
3337
3341
log .debug ("Added pool for host %s to session" , host )
3338
3342
if previous :
@@ -3372,7 +3376,7 @@ def update_created_pools(self):
3372
3376
# to allow us to attempt connections to hosts that have gone from ignored to something
3373
3377
# else.
3374
3378
if distance != HostDistance .IGNORED and host .is_up in (True , None ):
3375
- future = self .add_or_renew_pool (host , False )
3379
+ future = self .add_or_renew_pool (host , False , require_previous_shutdown_or_none = True )
3376
3380
elif distance != pool .host_distance :
3377
3381
# the distance has changed
3378
3382
if distance == HostDistance .IGNORED :
0 commit comments