diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 06e6293ef..8b9a012b6 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -1980,7 +1980,7 @@ def on_up(self, host): futures_results = [] callback = partial(self._on_up_future_completed, host, futures, futures_results, futures_lock) for session in tuple(self.sessions): - future = session.add_or_renew_pool(host, is_host_addition=False) + future = session.add_or_renew_pool(host, is_host_addition=False, require_previous_shutdown_or_none=False) if future is not None: have_future = True future.add_done_callback(callback) @@ -2119,7 +2119,7 @@ def future_completed(future): have_future = False for session in tuple(self.sessions): - future = session.add_or_renew_pool(host, is_host_addition=True) + future = session.add_or_renew_pool(host, is_host_addition=True, require_previous_shutdown_or_none=False) if future is not None: have_future = True futures.add(future) @@ -2650,7 +2650,7 @@ def __init__(self, cluster, hosts, keyspace=None): # create connection pools in parallel self._initial_connect_futures = set() for host in hosts: - future = self.add_or_renew_pool(host, is_host_addition=False) + future = self.add_or_renew_pool(host, is_host_addition=False, require_previous_shutdown_or_none=False) if future: self._initial_connect_futures.add(future) @@ -3273,7 +3273,7 @@ def __del__(self): # when cluster.shutdown() is called explicitly. pass - def add_or_renew_pool(self, host, is_host_addition): + def add_or_renew_pool(self, host, is_host_addition, require_previous_shutdown_or_none): """ For internal use only. """ @@ -3321,7 +3321,11 @@ def callback(pool, errors): self._lock.acquire() return False self._lock.acquire() - self._pools[host] = new_pool + if require_previous_shutdown_or_none and (previous and not previous.is_shutdown): + new_pool.shutdown() + return True + else: + self._pools[host] = new_pool log.debug("Added pool for host %s to session", host) if previous: @@ -3361,7 +3365,7 @@ def update_created_pools(self): # to allow us to attempt connections to hosts that have gone from ignored to something # else. if distance != HostDistance.IGNORED and host.is_up in (True, None): - future = self.add_or_renew_pool(host, False) + future = self.add_or_renew_pool(host, False, require_previous_shutdown_or_none=True) elif distance != pool.host_distance: # the distance has changed if distance == HostDistance.IGNORED: