@@ -4095,24 +4095,39 @@ def callback(pool, errors):
40954095 metadata_host = self .cluster .metadata .get_host_by_host_id (host .host_id )
40964096
40974097 target_host = metadata_host if metadata_host is not None else host
4098- target_host_matches = False
4099- for pool_host in tuple (retained_pools ):
4100- if pool_host is target_host :
4101- target_host_matches = True
4102- elif pool_host == target_host :
4103- previous_pools .append (retained_pools .pop (pool_host ))
4104-
4105- if target_host_matches :
4106- reuse_existing_pool = True
4098+ target_endpoint_changed = False
4099+ if target_host is not host :
4100+ with target_host .lock :
4101+ target_endpoint_changed = not self ._endpoints_match (
4102+ target_host .endpoint , creation_endpoint )
4103+
4104+ if target_endpoint_changed :
4105+ log .debug (
4106+ "Discarding stale connection pool for host %s; "
4107+ "metadata host endpoint changed from %s" ,
4108+ host , creation_endpoint )
4109+ self ._invalidate_pool_creation (
4110+ host , expected_endpoint = creation_endpoint )
4111+ discard_pool = True
41074112 else :
4108- source_host = new_pool .host
4109- if (source_host is not target_host and
4110- target_host .sharding_info is None ):
4111- target_host .sharding_info = source_host .sharding_info
4112- new_pool .host = target_host
4113- retained_pools [target_host ] = new_pool
4114- self ._pools = retained_pools
4115- self ._clear_pool_creation (host , creation_epoch )
4113+ target_host_matches = False
4114+ for pool_host in tuple (retained_pools ):
4115+ if pool_host is target_host :
4116+ target_host_matches = True
4117+ elif pool_host == target_host :
4118+ previous_pools .append (retained_pools .pop (pool_host ))
4119+
4120+ if target_host_matches :
4121+ reuse_existing_pool = True
4122+ else :
4123+ source_host = new_pool .host
4124+ if (source_host is not target_host and
4125+ target_host .sharding_info is None ):
4126+ target_host .sharding_info = source_host .sharding_info
4127+ new_pool .host = target_host
4128+ retained_pools [target_host ] = new_pool
4129+ self ._pools = retained_pools
4130+ self ._clear_pool_creation (host , creation_epoch )
41164131
41174132 if reuse_existing_pool :
41184133 log .debug ("Reusing existing connection pool for host %s" , host )
0 commit comments