You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/12/16 12:23:25 UTC

[tinkerpop] 01/01: TINKERPOP-2266 Start keep alive polling on Connection construction

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2266
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit af4382211af12288dd1f550f17a4f95e0c1852a5
Author: stephen <sp...@gmail.com>
AuthorDate: Mon Dec 16 07:20:42 2019 -0500

    TINKERPOP-2266 Start keep alive polling on Connection construction
    
    If nothing writes to the Connection then keep alive doesn't start which might let it die in the pool if it is not used at some point.
---
 CHANGELOG.asciidoc                                            |  1 +
 .../java/org/apache/tinkerpop/gremlin/driver/Connection.java  | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 8f2909c..f0674c9 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 * Made `Cluster` be able to open configuration file on resources directory.
 * Bump to Tornado 5.x for gremlin-python.
+* Started keep-alive polling on `Connection` construction to ensure that a `Connection` doesn't die in the pool.
 * Deprecated `TraversalStrategies.applyStrategies()`.
 * Deprecated Jython support in `gremlin-python`.
 * Reverted: Modified Java driver to use IP address rather than hostname to create connections.
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 e700d49..ba18ddb 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
@@ -113,6 +113,8 @@ final class Connection {
             channelizer.connected();
 
             logger.info("Created new connection for {}", uri);
+
+            scheduleKeepAlive();
         } catch (Exception ie) {
             logger.debug("Error opening connection on {}", uri);
             throw new ConnectionException(uri, "Could not open connection", ie);
@@ -244,6 +246,13 @@ final class Connection {
                 });
         channel.writeAndFlush(requestMessage, requestPromise);
 
+        scheduleKeepAlive();
+
+        return requestPromise;
+    }
+
+    private void scheduleKeepAlive() {
+        final Connection thisConnection = this;
         // try to keep the connection alive if the channel allows such things - websockets will
         if (channelizer.supportsKeepAlive() && keepAliveInterval > 0) {
 
@@ -263,8 +272,6 @@ final class Connection {
             // through on the connection
             if (oldKeepAliveFuture != null) oldKeepAliveFuture.cancel(true);
         }
-
-        return requestPromise;
     }
 
     public void returnToPool() {