# ElasticSearch 2.2 Bulkload TransportException: TransportService is closed stopped can't send request

**URL:** <https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673>\
**Category:** Elasticsearch\
**Created:** [February 12, 2016, 11:17pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673 "2016-02-12T23:17:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveenK](https://avatars.discourse-cdn.com/v4/letter/p/cab0a1/32.png) [@praveenK](https://discuss.elastic.co/u/praveenK)\
**Post date:** [February 12, 2016, 11:17pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/1 "2016-02-12T23:17:52Z")

</div>

We upgraded the elasticsearch cluster from 2.1.1 to 2.2. Our bulk load process through bulkload processor which was working before with 2.1.1 is now throwing the following exception. Please let me know if i am missing something.

> [main] INFO org.elasticsearch.plugins - [Masque] modules , plugins , sites   
> [main] INFO com.zu.bids.rt.ESTest - Going to execute new bulk composed of 100 actions  
> [elasticsearch[Masque][listener][T#1]] WARN com.zu.bids.rt.ESTest - Error executing bulk  
> SendRequestTransportException[[Tutinax the Mountain-Mover][elasticsearch-master-01/10.240.0.22:9300][indices:data/write/bulk]]; nested: TransportException[TransportService is closed stopped can't send request];  
> at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:323)  
> at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:51)  
> at org.elasticsearch.client.transport.support.TransportProxyClient$1.doWithNode(TransportProxyClient.java:58)  
> at org.elasticsearch.client.transport.TransportClientNodesService$RetryListener.onFailure(TransportClientNodesService.java:247)  
> at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)  
> at org.elasticsearch.transport.TransportService$Adapter$3.run(TransportService.java:588)  
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
> at java.lang.Thread.run(Thread.java:745)  
> Caused by: TransportException[TransportService is closed stopped can't send request]  
> at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:303)  
> ... 8 more

Test Code is below:

> public class ESTest {

> ```
> private static final Logger LOG = LoggerFactory.getLogger(ESTest.class);
> 
> ```

> ```
> public static void main(String[] args) throws IOException {
> 
> ```

> ```
> String[] esnodes = "elasticsearch-master-01:9300,elasticsearch-master-02:9300,elasticsearch-master-03:9300"
> .split(",");
> Settings settings = Settings.builder().put("cluster.name", "zuelasticsearch")
> .put("client.transport.sniff", false).put("client.transport.ping_timeout", 20, TimeUnit.SECONDS)
> .build();
> 
> ```

> ```
> TransportClient tclient = TransportClient.builder().settings(settings).build();
> for (String node : esnodes) {
> String[] host = node.split(":");
> tclient.addTransportAddress(
> new InetSocketTransportAddress(InetAddress.getByName(host[0]), Integer.valueOf(host[1])));
> }
> 
> ```

> ```
> Client client = tclient;
> 
> ```

> ```
> BulkProcessor bulkProcessor = getBulkProcessor(client, 3000, 3);
> 
> ```

> ```
> String[] strs = { "This", "is", "a", "good", "test" };
> 
> ```

> ```
> for (int i = 0; i < 100; i++) {
> 
> ```

> ```
> XContentBuilder jsonBuilder = XContentFactory.jsonBuilder().startObject();
> jsonBuilder.field(String.valueOf(i), strs[i % 5]);
> jsonBuilder.endObject();
> bulkProcessor
> .add(client.prepareIndex("remtest", "tello", String.valueOf(i)).setSource(jsonBuilder).request());
> }
> 
> ```

> ```
> bulkProcessor.close();
> client.close();
> 
> ```

> ```
> }
> 
> ```

> ```
> public static BulkProcessor getBulkProcessor(Client client, int nActions, int nConcurrentRequests) {
> return BulkProcessor.builder(client, new Listener() {
> public void beforeBulk(long executionId, BulkRequest request) {
> LOG.info("Going to execute new bulk composed of {} actions", request.numberOfActions());
> }
> 
> ```

> ```
> public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
> LOG.info("Executed bulk composed of {} actions", request.numberOfActions());
> }
> 
> ```

> ```
> public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
> LOG.warn("Error executing bulk", failure);
> }
> 
> ```

> ```
> }).setBulkActions(nActions).setConcurrentRequests(nConcurrentRequests).build();
> }
> 
> ```

> }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2016, 7:16am UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/2 "2016-02-13T07:16:15Z")

</div>

Short hack: add a wait period before closing the client.

The problem here is that closing the bulk is supposed to flush the bulk but it the client is closed at the same time, it fails to perform the bulk.

I'd also add a FlushInterval to the bulk processor but it's not related to your issue.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 13, 2016, 1:42pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/3 "2016-02-13T13:42:47Z")

</div>

Add an explicit `awaitClose` call to wait for all outstanding bulk requests, e.g.

```auto
bulkProcessor.awaitClose(30L, TimeUnit.SECONDS);
bulkProcessor.close();
client.close();

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2016, 2:25pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/4 "2016-02-13T14:25:35Z")

</div>

w00t. I never realized it was documented at [https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.2/java-docs-bulk-processor.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.2/java-docs-bulk-processor.html).

Thanks Jorg.

---

<div class="post-metadata">

**Author:** ![praveenK](https://avatars.discourse-cdn.com/v4/letter/p/cab0a1/32.png) [@praveenK](https://discuss.elastic.co/u/praveenK)\
**Post date:** [February 16, 2016, 2:33pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/5 "2016-02-16T14:33:39Z")

</div>

@dadoonet @jprante Thanks for the answers. Your solution is working fine most of the times.. but it is still failing few times. Is there any better calculation for the wait time. ??

---

<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:** [July 5, 2017, 11:16pm UTC](https://discuss.elastic.co/t/elasticsearch-2-2-bulkload-transportexception-transportservice-is-closed-stopped-cant-send-request/41673/6 "2017-07-05T23:16:01Z")

</div>


