Elffuss BraidHub

kikocis/java-driver public

Merge pull request #155 from shaochuan/1.0-leak-fix

Fix connection leaks in exception code paths
Changeset58739bfde29aacf486cd15c8757b93cf1dc94e66f1e220de03e22980d9cde2f3
AuthorSylvain Lebresne <sylvain@datastax.com> · 2014-02-24 15:05 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2014-02-24 15:05 +01:00
Parents6a3c42810091, 833cc0dfd10d

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +6 −1
@@ -153,7 +153,12 @@
153153 */
154154 public Session connect(String keyspace) {
155155 SessionManager session = (SessionManager)connect();
156- session.setKeyspace(keyspace);
156+ try {
157+ session.setKeyspace(keyspace);
158+ } catch (RuntimeException e) {
159+ session.shutdown();
160+ throw e;
161+ }
157162 return session;
158163 }
159164
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +4 −0
@@ -219,7 +219,11 @@
219219 refreshSchema(connection, null, null, cluster);
220220 return connection;
221221 } catch (BusyConnectionException e) {
222+ connection.close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
222223 throw new DriverInternalError("Newly created connection should not be busy");
224+ } catch (RuntimeException e) {
225+ connection.close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
226+ throw e;
223227 }
224228 }
225229