Elffuss BraidHub

kikocis/java-driver public

Ensure connections are cleaned up when pool construction fails.
Changeset47df60f15f7507869cad3fb057aafc4285be968acbafcd4d8842156ddb3dce94
Authorolim7t <omichallat+github@gmail.com> · 2014-12-18 11:02 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-12-19 00:16 +01:00
Parentsa3cf912d769e

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +17 −4
@@ -88,11 +88,17 @@
8888 Thread.currentThread().interrupt();
8989 // If asked to interrupt, we can skip opening core connections, the pool will still work.
9090 // But we ignore otherwise cause I'm not sure we can do much better currently.
91+ } catch (ConnectionException e) {
92+ forceClose(l);
93+ throw e;
94+ } catch (UnsupportedProtocolVersionException e) {
95+ forceClose(l);
96+ throw e;
97+ } catch (ClusterNameMismatchException e) {
98+ forceClose(l);
99+ throw e;
91100 } 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- }
101+ forceClose(l);
96102 throw e;
97103 }
98104 this.connections = new CopyOnWriteArrayList<PooledConnection>(l);
@@ -101,6 +107,13 @@
101107 logger.trace("Created connection pool to host {}", host);
102108 }
103109
110+ // Clean up if we got an error at construction time but still created part of the core connections
111+ private void forceClose(List<PooledConnection> l) {
112+ for (PooledConnection connection : l) {
113+ connection.closeAsync().force();
114+ }
115+ }
116+
104117 private PoolingOptions options() {
105118 return manager.configuration().getPoolingOptions();
106119 }