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

java.net.SocketException: Connection reset

Open andyflury opened this issue 9 years ago • 15 comments

We are getting a strange error when pulling a lot of data through chunking.

java.lang.RuntimeException: java.net.SocketException: Connection reset
	at org.influxdb.impl.InfluxDBImpl$1.onResponse(InfluxDBImpl.java:384)
	at retrofit2.OkHttpCall$1.callSuccess(OkHttpCall.java:132)
	at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:111)
	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(Unknown Source)
	at java.net.SocketInputStream.read(Unknown Source)
	at okio.Okio$2.read(Okio.java:138)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
	at okio.RealBufferedSource.read(RealBufferedSource.java:45)
	at okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:429)
	at okio.RealBufferedSource.read(RealBufferedSource.java:45)
	at okio.RealBufferedSource.exhausted(RealBufferedSource.java:55)
	at okio.InflaterSource.refill(InflaterSource.java:101)
	at okio.InflaterSource.read(InflaterSource.java:62)
	at okio.GzipSource.read(GzipSource.java:80)
	at okio.RealBufferedSource.read(RealBufferedSource.java:45)
	at okio.ForwardingSource.read(ForwardingSource.java:35)
	at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:285)
	at okio.RealBufferedSource.request(RealBufferedSource.java:66)
	at com.squareup.moshi.JsonUtf8Reader.peekNumber(JsonUtf8Reader.java:401)
	at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:335)
	at com.squareup.moshi.JsonUtf8Reader.hasNext(JsonUtf8Reader.java:163)
	at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:74)
	at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:52)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:75)
	at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:52)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.ClassJsonAdapter$FieldBinding.read(ClassJsonAdapter.java:204)
	at com.squareup.moshi.ClassJsonAdapter.fromJson(ClassJsonAdapter.java:166)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:75)
	at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:52)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.ClassJsonAdapter$FieldBinding.read(ClassJsonAdapter.java:204)
	at com.squareup.moshi.ClassJsonAdapter.fromJson(ClassJsonAdapter.java:166)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:75)
	at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:52)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.ClassJsonAdapter$FieldBinding.read(ClassJsonAdapter.java:204)
	at com.squareup.moshi.ClassJsonAdapter.fromJson(ClassJsonAdapter.java:166)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:127)
	at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:34)
	at org.influx

We are pulling about 200'000 datapoints in total, which takes the application about 1.5 hours to process. Originally we have used chunkSize=10000, then we reduced it to 1000 and 200. The lower the chunkSize the longer it takes for the Exception to show up.

Any idea what might be causing this?

andyflury avatar May 16 '17 17:05 andyflury

Connection reset is send from the receiving side, i guess you have to tune tcp the influxdb server.

majst01 avatar May 17 '17 06:05 majst01

Thanks Stefan, we are using the default influxdb server settings, any ideas what to look for?

andyflury avatar May 17 '17 07:05 andyflury

google for linux server ip tuning and friends:

This might be a good starting point: http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/

majst01 avatar May 17 '17 07:05 majst01

Thanks! We are actually running on a Windows Server 2016 VM on Amazon AWS. Interesting enough we do not get the same error when running it on a local Windows 10 Laptop! Thanks for your help!

andyflury avatar May 17 '17 07:05 andyflury

Oh, this at least shows that this is a tcp tuning related issue. But on Windows im out of deep knowledge.

majst01 avatar May 17 '17 08:05 majst01

So you think it is related to OS network settings and not InfluxDB Server, InfluxDB JavaClient, OKHttp?

andyflury avatar May 17 '17 08:05 andyflury

It is the OS tuning and might be InfluxDB Server as well but OKHttp and Java Client is most probably not

majst01 avatar May 17 '17 08:05 majst01

any news on this topic, please close if possible.

majst01 avatar Jun 15 '17 15:06 majst01

Hi Stefan, yes, we did some more investigation on the topic but could never find out the root cause. What we should do is to let the consumer know if there is a IOException and then he can decide what he wants to do. At the moment we simply throw the exception and since this happens in a separate thread the consumer will not be notified. Let me create a merge request on this

andyflury avatar Jun 15 '17 15:06 andyflury

BTW, are you planning on doing a release some time soon?

andyflury avatar Jun 15 '17 15:06 andyflury

OK, I created a pull request #338. As I cannot simulate an IOException during testing so unfortunately the code coverage test fails. I hope that is ok with you.

andyflury avatar Jun 15 '17 16:06 andyflury

Yes next release should come in ~2 weeks, nothing special is waiting.

majst01 avatar Jun 19 '17 07:06 majst01

I am running on Windows with version 1.3.2 and the Java client. Whenever i do query that includes a where and group by i get the above error. It is a small set of data and works in the CLI. It only takes milliseconds to run in the CLI

mknutty avatar Aug 18 '17 19:08 mknutty

We have experienced the same issue when adding GROUP BY time() to a simple query. We are still investigating, but the current workaround implemented addresses the URLEncoding in the org.influxdb.dto.Query class:

import org.influxdb.dto.Query;

public class MyQuery extends Query {
	public MyQuery(String command, String database) {
		super(command, database);
	}

	@Override
	public String getCommandWithUrlEncoded() {
		return super.getCommandWithUrlEncoded().replace("+", "%20");
	}
}

Who has experience with encoding URLs?

ewoudwerkman avatar Feb 20 '18 19:02 ewoudwerkman

Connection reset simply means that a TCP RST was received. TCP RST packet is that the remote side telling you the connection on which the previous TCP packet is sent is not recognized, maybe the connection has closed, maybe the port is not open, and something like these. A reset packet is simply one with no payload and with the RST bit set in the TCP header flags.

There are several possible causes.

  • The other end has deliberately reset the connection.
  • Writing to a connection that the other end has already closed
  • Closing a java socket when there is unread data in the socket receive buffer.
  • In Windows, 'software caused connection abort', which is not the same as 'connection reset', is caused by network problems sending from your end.

linehammer avatar Jan 06 '21 04:01 linehammer