You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/03/25 17:53:50 UTC

[16/24] incubator-tinkerpop git commit: TINKERPOP-1239 Connections were not be returned to the connection pool properly.

TINKERPOP-1239 Connections were not be returned to the connection pool properly.

Excessive failures quickly drained the pool and resulted in TimeoutException for the driver. The fix was fairly simple as some poorly placed curly braces (or lack of curly braces) didn't allow an important line of code to execute. Added a test to validate that things were behaving properly now. CTR


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2a2086c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2a2086c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2a2086c0

Branch: refs/heads/TINKERPOP-1236
Commit: 2a2086c01716a4ceb654ade2cf07da3fbf271ab1
Parents: 80a47c6
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 25 07:49:49 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 25 07:51:44 2016 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/Connection.java    |  5 +++--
 .../server/GremlinDriverIntegrateTest.java      | 21 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a2086c0/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
index 5fc0e48..a5dd7d5 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
@@ -210,10 +210,11 @@ final class Connection {
                         // succeed. instead, the Connection gets replaced which destroys the dead channel on the
                         // client and allows a new one to be reconstructed.
                         readCompleted.exceptionally(t -> {
-                            if (t instanceof IOException)
+                            if (t instanceof IOException) {
                                 if (pool != null) pool.replaceConnection(thisConnection);
-                            else
+                            } else {
                                 thisConnection.returnToPool();
+                            }
 
                             // close was signaled in closeAsync() but there were pending messages at that time. attempt
                             // the shutdown if the returned result cleared up the last pending message

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a2086c0/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index 054e0ca..6912545 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -130,6 +130,27 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
     }
 
     @Test
+    public void shouldEventuallySucceedAfterMuchFailure() throws Exception {
+        final Cluster cluster = Cluster.build().addContactPoint("localhost").create();
+        final Client client = cluster.connect();
+
+        // tested independently to 10000 iterations but for speed, bumped back to 1000
+        IntStream.range(0,1000).forEach(i -> {
+            try {
+                client.submit("1 + 9 9").all().join().get(0).getInt();
+                fail("Should not have gone through due to syntax error");
+            } catch (Exception ex) {
+                final Throwable root = ExceptionUtils.getRootCause(ex);
+                assertThat(root, instanceOf(ResponseException.class));
+            }
+        });
+
+        assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+
+        cluster.close();
+    }
+
+    @Test
     public void shouldEventuallySucceedOnSameServer() throws Exception {
         stopServer();