Elffuss BraidHub

kikocis/java-driver public

Don't release connection when we reuse it to prepare query (JAVA-651).

Fixed as part of JAVA-651 to avoid releasing the connection twice. This
also fixes the issues raised in JAVA-633.
Changesetb71ec2203d70994ea4d39138ee41e63be226e75caca49c09588f5444ffca0290
Authorolim7t <omichallat+github@gmail.com> · 2015-02-06 14:41 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-02-11 12:34 +01:00
Parents2f29ae9aea6b

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +8 −3
@@ -293,10 +293,8 @@
293293 }
294294
295295 Host queriedHost = current;
296+ boolean releaseConnection = true;
296297 try {
297- if (connection instanceof PooledConnection)
298- ((PooledConnection)connection).release();
299-
300298 switch (response.type) {
301299 case RESULT:
302300 setFinalResult(connection, response);
@@ -420,6 +418,7 @@
420418 }
421419
422420 try {
421+ releaseConnection = false; // we're reusing it for the prepare call
423422 write(connection, prepareAndRetry(toPrepare.getQueryString()));
424423 } finally {
425424 // Always reset the previous keyspace if needed
@@ -467,6 +466,9 @@
467466 } catch (Exception e) {
468467 setFinalException(connection, e);
469468 } finally {
469+ if (releaseConnection && connection instanceof PooledConnection)
470+ ((PooledConnection)connection).release();
471+
470472 if (queriedHost != null)
471473 manager.cluster.manager.reportLatency(queriedHost, latency);
472474 }
@@ -495,6 +497,9 @@
495497 return;
496498 }
497499
500+ if (connection instanceof PooledConnection)
501+ ((PooledConnection)connection).release();
502+
498503 // TODO should we check the response ?
499504 switch (response.type) {
500505 case RESULT: