microsoft / spring-data-gremlin

We are in the process of deprecating Spring Data Gremlin. -- Provide generic annotation oriented programming form based on gremlin for graph database
Other
129 stars 76 forks source link

GremlinFactory bug, connection pool is not reusable #225

Closed apetropavlovskiy closed 5 years ago

apetropavlovskiy commented 5 years ago

Expected Behavior

GremlinFactory must return precached Client (org.apache.tinkerpop.gremlin.driver.Client)

Current Behavior

GremlinFactory create new non reusable pooled connections on each database operations. Thus after some time Gremlin driver thows an exceptions related by buffer overflow, timeouts.

   public Client getGremlinClient() {
        if (this.gremlinCluster == null) {
            this.gremlinCluster = this.createGremlinCluster();
        }
       // Create connection pool with size 2 each time. Memory leak.
       // Unexpexted behavior after some tme
        return this.gremlinCluster.connect();
    }

Possible Solution

Extend GremlinFactory by custom @Component implementation like:

    public Client getGremlinClient() {
        if (this.gremlinCluster == null || this.gremlinCluster.isClosed() || this.gremlinCluster.isClosing()) {
            this.gremlinCluster = this.getGremlinCluster();
        }
        if (this.client == null || this.client.isClosing()) {
            this.client = this.gremlinCluster.connect();
        }
        return this.client;
    }

and register it as @Bean @Primary in Spring context.

Steps to Reproduce (for bugs)

Just try to store some huge data to the Gremlin