Skip to content

Commit af88286

Browse files
fbaroAlexandre Dutra
authored andcommitted
Avoid Session leak using connect() with wrong keyspace name (JAVA-806)
1 parent 2e877fc commit af88286

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

  • driver-core/src/main/java/com/datastax/driver/core

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,16 @@ public Session connect(String keyspace) {
280280
long timeout = getConfiguration().getSocketOptions().getConnectTimeoutMillis();
281281
Session session = connect();
282282
try {
283-
ResultSetFuture future = session.executeAsync("USE " + keyspace);
284-
// Note: using the connection timeout isn't perfectly correct, we should probably change that someday
285-
Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS);
286-
return session;
287-
} catch (TimeoutException e) {
288-
throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout));
289-
} catch (ExecutionException e) {
290-
throw DefaultResultSetFuture.extractCauseFromExecutionException(e);
283+
try {
284+
ResultSetFuture future = session.executeAsync("USE " + keyspace);
285+
// Note: using the connection timeout isn't perfectly correct, we should probably change that someday
286+
Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS);
287+
return session;
288+
} catch (TimeoutException e) {
289+
throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout));
290+
} catch (ExecutionException e) {
291+
throw DefaultResultSetFuture.extractCauseFromExecutionException(e);
292+
}
291293
} catch (RuntimeException e) {
292294
session.close();
293295
throw e;

0 commit comments

Comments
 (0)