Elffuss BraidHub

kikocis/java-driver public

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.
Changeset3cb9a3ede2468a1ee3e238f2eb7b018863b4c6bbae7249687ceac5abe36bdc66
Authorolim7t <omichallat+github@gmail.com> · 2014-12-19 00:08 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-12-19 00:33 +01:00
Parents0fe9369e8f1b

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -17,6 +17,8 @@
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:
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +7 −5
@@ -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 @@
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 @@
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 @@
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) {