monali01
monali01

Reputation: 170

Gremlin server withRemote connection closed - how to reconnect automatically?

I am using withRemote to connect my java application to gremlin server running in AWS with dynamodb storage backend. I am getting connection timeout after few seconds (~3.3 seconds):

org.apache.tinkerpop.gremlin.process.remote.RemoteConnectionException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.nio.channels.ClosedChannelException]]

I need to figure out how to reconnect which means detecting if the connection is closed. I am not sure how to detect that. I get the above exception when I use the graph traversal, is there a way to discover it before and reconnect or is there an option in configuration that allows reconnecting automatically (like create new connection before this one closes) so my application is always connected?

In case you need, this is how I am doing connection - currently connection part is singleton when the application starts:

  this.graph = EmptyGraph.instance();
  GryoMessageSerializerV1d0 gryoMessageSerializerV1d0 = new GryoMessageSerializerV1d0(
        GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()));
  this.cluster = Cluster.build().serializer(gryoMessageSerializerV1d0)
        .addContactPoint(configuration.getString("graphDb.host", "localhost"))
        .port(configuration.getInt("graphDb.port", 8182)).create();
  this.graphTraversalSource = this.graph.traversal().withRemote(DriverRemoteConnection.using(cluster));

Upvotes: 3

Views: 4681

Answers (1)

stephen mallette
stephen mallette

Reputation: 46226

I feel like this problem is already solved with connection.keepAlive configuration option. It defaults to 180 seconds so it's longer than your timeout of 60 seconds in your load balancer which is why it gives up.

That said, the driver should be reconnecting on its own. It's constantly trying to do that given the connectionPool.reconnectInterval but perhaps there is a condition where you're quickly exhausting all the connections to the point of getting that error....not sure. Either way, hopefully the

Upvotes: 2

Related Questions