InfluxDBIOException: java.net.SocketTimeoutException: timeout with java client

I’m using influxdb java client. When multiple requests are sent , org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout error is seen.

The exception occurs at the below statement.

val q = Query(
“select sum(firstCount) as totalFirstCount, sum(secondCount) as totalSecondCount” +
" ,sum(thirdCount) as totalThirdCount, sum(fourthCount) as totalFourthCount " +
“from counters where time > now() - “1h” group by field1 , field2”,
“dbname”)

The explain statement returns
EXPRESSION: sum(firstCount::integer) NUMBER OF SHARDS: 123 NUMBER OF SERIES: 26568 CACHED VALUES: 105408 NUMBER OF FILES: 16200 NUMBER OF BLOCKS: 16200 SIZE OF BLOCKS: 76693173

EXPRESSION: sum(secondCount::integer) NUMBER OF SHARDS: 123 NUMBER OF SERIES: 26568 CACHED VALUES: 105408 NUMBER OF FILES: 16200 NUMBER OF BLOCKS: 16200 SIZE OF BLOCKS: 86133364

EXPRESSION: sum(thirdCount::integer) NUMBER OF SHARDS: 123 NUMBER OF SERIES: 26568 CACHED VALUES: 105408 NUMBER OF FILES: 16200 NUMBER OF BLOCKS: 16200 SIZE OF BLOCKS: 61967770

EXPRESSION: sum(fourthCount::integer) NUMBER OF SHARDS: 123 NUMBER OF SERIES: 26568 CACHED VALUES: 105408 NUMBER OF FILES: 16200 NUMBER OF BLOCKS: 16200 SIZE OF BLOCKS: 61967754

The exception occurs frequently with more data. Is this related to the size of the DB or any suggestions?

Your Java socket is timing out (throws java.net.SocketTimeoutException: Connection timed out) means that it takes too long to get respond from other device and your request expires before getting response.

You can effectively handle it from client side by define a connection timeout and later handle it by using a try/catch/finally block. You can use the connect(SocketAddress endpoint, int timeout) method and set the timeout parameter:

Socket socket = new Socket();
SocketAddress socketAddress = new InetSocketAddress(host, port);
socket.connect(socketAddress, 12000); //12000 are milli seconds

From server side you can use the setSoTimeout(int timeout) method to set a timeout value. The timeout value defines how long the ServerSocket.accept() method will block:

ServerSocket serverSocket = new new ServerSocket(port);
serverSocket.setSoTimeout(12000);

So to avoid this exception in another way, you should keep the connection be alive using the method Socket.setKeepAlive() method although possibly you have not used the method setTimeout() , meaning asking the socket to unlimited block to receive.