kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 47198e2e04ca8b5355c0058b05336dde2c8dbcbb59f835288787b7d1df3171f4 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-15 18:24 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-15 19:28 +02:00 |
| Parents | 736d1b430942 |
2 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | - [improvement] Expose close method on load balancing policy (JAVA-463) |
| 15 | 15 | - [improvement] Allow load balancing policy to trigger refresh for a single host (JAVA-459) |
| 16 | 16 | - [bug] Expose an API to cancel reconnection attempts (JAVA-493) |
| 17 | +- [bug] Fix NPE when a connection fails during pool construction (JAVA-503) | |
| 17 | 18 | |
| 18 | 19 | |
| 19 | 20 | 2.0.6: |
modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +10 −0
| @@ -29,6 +29,7 @@ | ||
| 29 | 29 | import java.util.concurrent.locks.Lock; |
| 30 | 30 | import java.util.concurrent.locks.ReentrantLock; |
| 31 | 31 | |
| 32 | +import com.google.common.collect.Lists; | |
| 32 | 33 | import com.google.common.util.concurrent.MoreExecutors; |
| 33 | 34 | import org.slf4j.Logger; |
| 34 | 35 | import org.slf4j.LoggerFactory; |
| @@ -87,6 +88,12 @@ | ||
| 87 | 88 | Thread.currentThread().interrupt(); |
| 88 | 89 | // If asked to interrupt, we can skip opening core connections, the pool will still work. |
| 89 | 90 | // But we ignore otherwise cause I'm not sure we can do much better currently. |
| 91 | + } catch (RuntimeException e) { | |
| 92 | + // Rethrow but make sure to properly close the connections in our temporary list. | |
| 93 | + for (PooledConnection connection : l) { | |
| 94 | + connection.closeAsync().force(); | |
| 95 | + } | |
| 96 | + throw e; | |
| 90 | 97 | } |
| 91 | 98 | this.connections = new CopyOnWriteArrayList<PooledConnection>(l); |
| 92 | 99 | this.open = new AtomicInteger(connections.size()); |
| @@ -410,6 +417,9 @@ | ||
| 410 | 417 | } |
| 411 | 418 | |
| 412 | 419 | private List<CloseFuture> discardAvailableConnections() { |
| 420 | + // This can happen if creating the connections in the constructor fails | |
| 421 | + if (connections == null) | |
| 422 | + return Lists.newArrayList(CloseFuture.immediateFuture()); | |
| 413 | 423 | |
| 414 | 424 | List<CloseFuture> futures = new ArrayList<CloseFuture>(connections.size()); |
| 415 | 425 | for (final PooledConnection connection : connections) { |