influxdb-java icon indicating copy to clipboard operation
influxdb-java copied to clipboard

Connection to influx still active even after calling influxdb.close();

Open saif-17 opened this issue 7 years ago • 2 comments

Connection to influx still active even after calling influxdb.close();

Here is my Test Code

   public static void main (String[]args){
            InfluxDB influxDBConnection;

            for (int i = 0; i < 10; i++) {
                try {
                    QueryResult queryResult;
                    influxDBConnection = InfluxDBFactory.connect("url", "username", "password");
                    queryResult = influxDBConnection.query(new Query("select value1 from test_measurement1", "test_db"));
                    System.out.println(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
                    influxDBConnection.close();
                    Thread.sleep(10000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

After execution of following code 10 connections are made even after calling the close method. I checked the number of connection made to influxdb through netstat.

Is there any way to close the existing influx connection?

saif-17 avatar Jun 12 '18 07:06 saif-17

@saif-17, the close method actually does not close the http connections held by the underlying okhttp client. Morover, okhttp always uses a connection pool of some idle connections and once a okhttp client has been initialized, shutdown of the client isn't necessary (https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html)

However May I ask if you run netstat after the main process had exited or just after the close method invoked ?

lxhoan avatar Jul 04 '18 16:07 lxhoan

I've tried 3 things:

  1. Before the program starts: The number of connection showed in netstat is 0 as only 1 program is making connection to Influx.

  2. When program is running The number of connection is increasing and increasing until the programs throws exception.

  3. After program exited The number of connection is back to 0.

I'm reusing same connection in the program but the connection is still increasing.

saif-17 avatar Jul 18 '18 06:07 saif-17