Skip to content

Commit 68408c0

Browse files
committed
Ensure updateCreatedPools does not add pools for suspected hosts (JAVA-593).
The check in replacePool is not part of the fix, but it was added as a security measure since it was where connections were leaked.
1 parent f7ecc5c commit 68408c0

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

driver-core/CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ CHANGELOG
1717
- [bug] Prevent faulty control connection from ignoring reconnecting hosts
1818
(JAVA-587)
1919
- temporarily revert "Add idle timeout to the connection pool" (JAVA-419)
20+
- [bug] Ensure updateCreatedPools does not add pools for suspected hosts
21+
(JAVA-593)
2022

2123

2224
2.0.8:

driver-core/src/main/java/com/datastax/driver/core/SessionManager.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.datastax.driver.core;
1717

18-
import java.net.InetAddress;
1918
import java.net.InetSocketAddress;
2019
import java.nio.ByteBuffer;
2120
import java.util.*;
@@ -30,7 +29,6 @@
3029
import org.slf4j.LoggerFactory;
3130

3231

33-
import com.datastax.driver.core.exceptions.AuthenticationException;
3432
import com.datastax.driver.core.exceptions.DriverInternalError;
3533
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
3634
import com.datastax.driver.core.policies.LoadBalancingPolicy;
@@ -270,7 +268,11 @@ private boolean replacePool(Host host, HostDistance distance, HostConnectionPool
270268
return false;
271269

272270
HostConnectionPool newPool = new HostConnectionPool(host, distance, this);
273-
pools.put(host, newPool);
271+
previous = pools.put(host, newPool);
272+
if (previous != null && !previous.isClosed()) {
273+
logger.warn("Replacing a pool that wasn't closed. Closing it now, but this was not expected.");
274+
previous.closeAsync();
275+
}
274276

275277
// If we raced with a session shutdown, ensure that the pool will be closed.
276278
if (isClosing)
@@ -348,7 +350,7 @@ void updateCreatedPools(ListeningExecutorService executor) {
348350
HostConnectionPool pool = pools.get(h);
349351

350352
if (pool == null) {
351-
if (dist != HostDistance.IGNORED && h.isUp())
353+
if (dist != HostDistance.IGNORED && h.state == Host.State.UP)
352354
poolCreationFutures.add(maybeAddPool(h, executor));
353355
} else if (dist != pool.hostDistance) {
354356
if (dist == HostDistance.IGNORED) {
@@ -381,7 +383,7 @@ void updateCreatedPools(Host h, ListeningExecutorService executor) {
381383

382384
try {
383385
if (pool == null) {
384-
if (dist != HostDistance.IGNORED && h.isUp())
386+
if (dist != HostDistance.IGNORED && h.state == Host.State.UP)
385387
maybeAddPool(h, executor).get();
386388
} else if (dist != pool.hostDistance) {
387389
if (dist == HostDistance.IGNORED) {

0 commit comments

Comments
 (0)