# An existing connection was forcibly closed by the remote host

**URL:** <https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246>\
**Category:** Elasticsearch\
**Created:** [January 15, 2021, 9:33am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246 "2021-01-15T09:33:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![279zlj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/279zlj/32/82323_2.png) [@279zlj](https://discuss.elastic.co/u/279zlj)\
**Post date:** [January 15, 2021, 9:33am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/1 "2021-01-15T09:33:42Z")

</div>

Exception in thread "main" java.io.IOException: 远程主机强迫关闭了一个现有的连接。  
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:964)  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:233)  
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1764)  
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1734)  
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1696)  
at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:928)  
at com.wuzhou.utils.EsUtil4Scala$.addOneDoc(EsUtil4Scala.scala:77)  
at com.wuzhou.calculateTest$.calculate(calculateTest.scala:132)  
at com.wuzhou.calculateTest$.main(calculateTest.scala:24)  
at com.wuzhou.calculateTest.main(calculateTest.scala)  
Caused by: java.io.IOException: 远程主机强迫关闭了一个现有的连接。  
at sun.nio.ch.SocketDispatcher.write0(Native Method)  
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)  
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)  
at sun.nio.ch.IOUtil.write(IOUtil.java:65)  
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)  
at org.apache.http.impl.nio.codecs.AbstractContentEncoder.doWriteChunk(AbstractCo

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [January 15, 2021, 10:29am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/2 "2021-01-15T10:29:47Z")

</div>

> [@279zlj](#):
>
> 远程主机强迫关闭了一个现有的连接

For those of us that don't read the language in which the exception message is written, it apparently translates to "The remote host forcibly closed an existing connection" as per the title.

What's your question @279zlj?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 18, 2021, 3:55am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/3 "2021-01-18T03:55:18Z")

</div>

Welcome to our community! 😃

To reiterate David's comments, posting a log entry with no extra information makes it very difficult to understand what you are looking for.

If English is not your native language, then we do have other language-specific categories here - [https://discuss.elastic.co/c/in-your-native-tongue/11](https://discuss.elastic.co/c/in-your-native-tongue/11)

---

<div class="post-metadata">

**Author:** ![279zlj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/279zlj/32/82323_2.png) [@279zlj](https://discuss.elastic.co/u/279zlj)\
**Post date:** [January 18, 2021, 5:37am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/4 "2021-01-18T05:37:53Z")

</div>

> [@279zlj](#):
>
> 远程主机强迫关闭了一个现有的连接

An error occurred when writing large amounts of data to elasticsearch: the remote host forcibly closed an existing connection. The error will not appear if the number of writes is reduced. Why?

---

<div class="post-metadata">

**Author:** ![279zlj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/279zlj/32/82323_2.png) [@279zlj](https://discuss.elastic.co/u/279zlj)\
**Post date:** [January 18, 2021, 5:38am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/5 "2021-01-18T05:38:35Z")

</div>

An error occurred when writing large amounts of data to elasticsearch: the remote host forcibly closed an existing connection. The error will not appear if the number of writes is reduced. Why?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 18, 2021, 5:54am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/6 "2021-01-18T05:54:39Z")

</div>

What version of Elasticsearch are you using?  
How do you know there are large amounts of writes happening? What is large?  
How are the writes being sent to Elasticsearch?  
What is the output from the `_cluster/stats?pretty&human` API?

---

<div class="post-metadata">

**Author:** ![279zlj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/279zlj/32/82323_2.png) [@279zlj](https://discuss.elastic.co/u/279zlj)\
**Post date:** [January 20, 2021, 6:32am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/7 "2021-01-20T06:32:03Z")

</div>

version:6.8.4  
Use spark to take out 120,000 pieces of data, splicing 120,000 pieces of data into a string, and write the error with es-hadoop. Later, test 1500W pieces of data without using splicing to write them one by one, but the last one or two million cannot be written.  
`_cluster/stats?pretty&human`output:  
{  
"\_nodes" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"cluster\_name" : "elasticsearch",  
"cluster\_uuid" : "QTfP-vDSSzeqrNzE-pOC5Q",  
"timestamp" : 1611123928272,  
"status" : "green",  
"indices" : {  
"count" : 14,  
"shards" : {  
"total" : 26,  
"primaries" : 26,  
"replication" : 0.0,  
"index" : {  
"shards" : {  
"min" : 1,  
"max" : 5,  
"avg" : 1.8571428571428572  
},  
"primaries" : {  
"min" : 1,  
"max" : 5,  
"avg" : 1.8571428571428572  
},  
"replication" : {  
"min" : 0.0,  
"max" : 0.0,  
"avg" : 0.0  
}  
}  
},  
"docs" : {  
"count" : 12784432,  
"deleted" : 23674  
},  
"store" : {  
"size" : "2.1gb",  
"size\_in\_bytes" : 2350123118  
},  
"fielddata" : {  
"memory\_size" : "0b",  
"memory\_size\_in\_bytes" : 0,  
"evictions" : 0  
},  
"query\_cache" : {  
"memory\_size" : "516.9kb",  
"memory\_size\_in\_bytes" : 529319,  
"total\_count" : 386,  
"hit\_count" : 0,  
"miss\_count" : 386,  
"cache\_size" : 3,  
"cache\_count" : 3,  
"evictions" : 0  
},  
"completion" : {  
"size" : "0b",  
"size\_in\_bytes" : 0  
},  
"segments" : {  
"count" : 76,  
"memory" : "9.9mb",  
"memory\_in\_bytes" : 10423911,  
"terms\_memory" : "7.8mb",  
"terms\_memory\_in\_bytes" : 8190039,  
"stored\_fields\_memory" : "733.5kb",  
"stored\_fields\_memory\_in\_bytes" : 751152,  
"term\_vectors\_memory" : "0b",  
"term\_vectors\_memory\_in\_bytes" : 0,  
"norms\_memory" : "3.6kb",  
"norms\_memory\_in\_bytes" : 3712,  
"points\_memory" : "757.4kb",  
"points\_memory\_in\_bytes" : 775648,  
"doc\_values\_memory" : "686.8kb",  
"doc\_values\_memory\_in\_bytes" : 703360,  
"index\_writer\_memory" : "0b",  
"index\_writer\_memory\_in\_bytes" : 0,  
"version\_map\_memory" : "0b",  
"version\_map\_memory\_in\_bytes" : 0,  
"fixed\_bit\_set" : "136.2kb",  
"fixed\_bit\_set\_memory\_in\_bytes" : 139512,  
"max\_unsafe\_auto\_id\_timestamp" : 1610603538037,  
"file\_sizes" : { }  
}  
},  
"nodes" : {  
"count" : {  
"total" : 1,  
"data" : 1,  
"coordinating\_only" : 0,  
"master" : 1,  
"ingest" : 1  
},  
"versions" : [  
"6.8.4"  
],  
"os" : {  
"available\_processors" : 16,  
"allocated\_processors" : 16,  
"names" : [  
{  
"name" : "Linux",  
"count" : 1  
}  
],  
"pretty\_names" : [  
{  
"pretty\_name" : "Ubuntu 18.04.5 LTS",  
"count" : 1  
}  
],  
"mem" : {  
"total" : "47.1gb",  
"total\_in\_bytes" : 50639941632,  
"free" : "9.2gb",  
"free\_in\_bytes" : 9881591808,  
"used" : "37.9gb",  
"used\_in\_bytes" : 40758349824,  
"free\_percent" : 20,  
"used\_percent" : 80  
}  
},  
"process" : {  
"cpu" : {  
"percent" : 0  
},  
"open\_file\_descriptors" : {  
"min" : 495,  
"max" : 495,  
"avg" : 495  
}  
},  
"jvm" : {  
"max\_uptime" : "5.2d",  
"max\_uptime\_in\_millis" : 449839381,  
"versions" : [  
{  
"version" : "1.8.0\_144",  
"vm\_name" : "Java HotSpot(TM) 64-Bit Server VM",  
"vm\_version" : "25.144-b01",  
"vm\_vendor" : "Oracle Corporation",  
"count" : 1  
}  
],  
"mem" : {  
"heap\_used" : "3.6gb",  
"heap\_used\_in\_bytes" : 3960643232,  
"heap\_max" : "7.8gb",  
"heap\_max\_in\_bytes" : 8476557312  
},  
"threads" : 178  
},  
"fs" : {  
"total" : "146.1gb",  
"total\_in\_bytes" : 156931440640,  
"free" : "92.2gb",  
"free\_in\_bytes" : 99064602624,  
"available" : "84.7gb",  
"available\_in\_bytes" : 91021606912  
},  
"plugins" : ,  
"network\_types" : {  
"transport\_types" : {  
"security4" : 1  
},  
"http\_types" : {  
"security4" : 1  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 20, 2021, 8:21pm UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/8 "2021-01-20T20:21:36Z")

</div>

Are you using the bulk API?

---

<div class="post-metadata">

**Author:** ![279zlj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/279zlj/32/82323_2.png) [@279zlj](https://discuss.elastic.co/u/279zlj)\
**Post date:** [January 21, 2021, 7:15am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/9 "2021-01-21T07:15:44Z")

</div>

I use two es-spark config on context init:  
`es.batch.size.bytes: 15mb`  
`es.batch.size.entries: 1000`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 18, 2021, 7:16am UTC](https://discuss.elastic.co/t/an-existing-connection-was-forcibly-closed-by-the-remote-host/261246/10 "2021-02-18T07:16:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
