Elffuss BraidHub

kikocis/java-driver public

Fix connection leaks in exception code paths
particularly when server is under extreme high loads,
it may throw RuntimeException, and in these exception
code paths, opened connections has to be closed
before returning the control to the caller.
Changeset833cc0dfd10ddfbf6d51d66402841df91daf70c13b5ab5841a82f6a29c2a4e68
AuthorShao-Chuan Wang <shaochuan.wang@bloomreach.com> · 2014-02-09 23:35 -08:00
CommitterShao-Chuan Wang <shaochuan.wang@bloomreach.com> · 2014-02-09 23:35 -08:00
Parentsffed01c5e379

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