# Executer/worker closing connection before trying to write, causing a SSLHandshakeException

**URL:** <https://discuss.elastic.co/t/executer-worker-closing-connection-before-trying-to-write-causing-a-sslhandshakeexception/123114>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [March 8, 2018, 3:55pm UTC](https://discuss.elastic.co/t/executer-worker-closing-connection-before-trying-to-write-causing-a-sslhandshakeexception/123114 "2018-03-08T15:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![viktorqt](https://avatars.discourse-cdn.com/v4/letter/v/e95f7d/32.png) [@viktorqt](https://discuss.elastic.co/u/viktorqt)\
**Post date:** [March 8, 2018, 3:55pm UTC](https://discuss.elastic.co/t/executer-worker-closing-connection-before-trying-to-write-causing-a-sslhandshakeexception/123114/1 "2018-03-08T15:55:59Z")

</div>

Hello,

around 1/3 of our files fail to write a DataFrame into Elasticsearch from our Spark-Application while using the ElasticSearch-Spark-Connector due to the following exception:  
org.elasticsearch.hadoop.rest.EsHadoopTransportException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Certificates seem to be correct, else it would fail 100% of the time..?!

We use Elasticsearch 6.1.3 and the "Elasticsearch Spark (for Spark 2.0) » 6.1.3"-Connector

The full Exception:  
¡error while spark execution=Job aborted due to stage failure: Task 0 in stage 3.0 failed 4 times, most recent failure: Lost task 0.3 in stage 3.0 (TID 7, [xxx.tb.de](http://xxx.tb.de), executor 1): org.elasticsearch.hadoop.rest.EsHadoopTransportException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake  
at org.elasticsearch.hadoop.rest.NetworkClient.execute(NetworkClient.java:124)  
at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:466)  
at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:430)  
at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:434)  
at org.elasticsearch.hadoop.rest.RestClient.get(RestClient.java:155)  
at org.elasticsearch.hadoop.rest.RestClient.getHttpNodes(RestClient.java:112)  
at org.elasticsearch.hadoop.rest.RestClient.getHttpDataNodes(RestClient.java:129)  
at org.elasticsearch.hadoop.rest.InitializationUtils.filterNonDataNodesIfNeeded(InitializationUtils.java:157)  
at org.elasticsearch.hadoop.rest.RestService.createWriter(RestService.java:581)  
at org.elasticsearch.spark.rdd.EsRDDWriter.write(EsRDDWriter.scala:58)  
at org.elasticsearch.spark.sql.EsSparkSQL$$anonfun$saveToEs$1.apply(EsSparkSQL.scala:101)  
at org.elasticsearch.spark.sql.EsSparkSQL$$anonfun$saveToEs$1.apply(EsSparkSQL.scala:101)  
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)  
at org.apache.spark.scheduler.Task.run(Task.scala:108)  
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:335)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)  
at java.lang.Thread.run(Thread.java:748)  
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake  
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1002)  
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)  
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:757)  
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)  
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)  
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)  
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828)  
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116)  
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)  
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)  
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)  
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)  
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)  
at org.elasticsearch.hadoop.rest.commonshttp.CommonsHttpTransport.execute(CommonsHttpTransport.java:478)  
at org.elasticsearch.hadoop.rest.NetworkClient.execute(NetworkClient.java:112)  
... 17 more  
Caused by: java.io.EOFException: SSL peer shut down incorrectly  
at sun.security.ssl.InputRecord.read(InputRecord.java:505)  
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)  
... 31 more

787a89a49cfc¡cause=org.elasticsearch.hadoop.rest.EsHadoopTransportException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

* * *

Executer logs:

Executor task launch worker for task 3, READ: TLSv1.2 Handshake, length = 333  
Executor task launch worker for task 3, READ: TLSv1.2 Handshake, length = 4  
Executor task launch worker for task 3, WRITE: TLSv1.2 Handshake, length = 70  
Executor task launch worker for task 3, WRITE: TLSv1.2 Change Cipher Spec, length = 1  
Executor task launch worker for task 3, WRITE: TLSv1.2 Handshake, length = 64  
Executor task launch worker for task 3, READ: TLSv1.2 Change Cipher Spec, length = 1  
Executor task launch worker for task 3, READ: TLSv1.2 Handshake, length = 64  
%% Cached client session: [Session-1, TLS\_ECDHE\_RSA\_WITH\_AES\_256\_CBC\_SHA]  
Executor task launch worker for task 3, WRITE: TLSv1.2 Application Data, length = 256  
Executor task launch worker for task 3, READ: TLSv1.2 Application Data, length = 2640  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)  
Executor task launch worker for task 3, SEND TLSv1.2 ALERT: warning, description = close\_notify  
Executor task launch worker for task 3, WRITE: TLSv1.2 Alert, length = 48  
Executor task launch worker for task 3, called closeSocket(true)  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)  
Executor task launch worker for task 3, WRITE: TLSv1.2 Handshake, length = 209  
Executor task launch worker for task 3, received EOFException: error  
Executor task launch worker for task 3, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake  
Executor task launch worker for task 3, SEND TLSv1.2 ALERT: fatal, description = handshake\_failure  
Executor task launch worker for task 3, WRITE: TLSv1.2 Alert, length = 2  
Executor task launch worker for task 3, Exception sending alert: java.net.SocketException: Broken pipe (Write failed)  
Executor task launch worker for task 3, called closeSocket()  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)  
Executor task launch worker for task 3, called close()  
Executor task launch worker for task 3, called closeInternal(true)

The "worker for task 3" is closing the connection before trying to WRITE/handshake(?) again, which causes an exception. Sometimes it works, sometimes it doesnt

We already tried setting all environments to TSL1, TSL1.1 and are currently using TSL1.2

Anyone any ideas? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![viktorqt](https://avatars.discourse-cdn.com/v4/letter/v/e95f7d/32.png) [@viktorqt](https://discuss.elastic.co/u/viktorqt)\
**Post date:** [March 12, 2018, 9:24am UTC](https://discuss.elastic.co/t/executer-worker-closing-connection-before-trying-to-write-causing-a-sslhandshakeexception/123114/2 "2018-03-12T09:24:41Z")

</div>

Hello,

wie fixed the problem:  
The IP-Whitelisting between Hadoop-Workernodes/ES-Masternode/ES-Datanode wasnt properly configured. Our Hadoop-Workernodes couldnt connect with the ES-Masternode.

Thanks

---

<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:** [April 9, 2018, 9:25am UTC](https://discuss.elastic.co/t/executer-worker-closing-connection-before-trying-to-write-causing-a-sslhandshakeexception/123114/3 "2018-04-09T09:25:10Z")

</div>

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