# Closing client on shutdown

**URL:** <https://discuss.elastic.co/t/closing-client-on-shutdown/14669>\
**Category:** Elasticsearch\
**Created:** [December 3, 2013, 6:05am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669 "2013-12-03T06:05:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasiliy\_S](https://avatars.discourse-cdn.com/v4/letter/v/91b2a8/32.png) [@Vasiliy\_S](https://discuss.elastic.co/u/Vasiliy_S)\
**Post date:** [December 3, 2013, 6:05am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/1 "2013-12-03T06:05:43Z")

</div>

Hi there,

According documentation[http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html),  
I need to close client on shutdown. What will be if don't do that? May it  
cause to memory leak on elasticsearch server side? Say, JVM with my  
application just shutdown unexpectedly without closing client. How will it  
affect on elasticsearch server that is launched in different JVM?

Thanks,  
Vasiliy

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3a33341b-9946-4953-9544-5e021fd05f67%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3a33341b-9946-4953-9544-5e021fd05f67%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [December 3, 2013, 8:55am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/2 "2013-12-03T08:55:16Z")

</div>

If client is shutdown unexpectedly, there will be errors in the server log,  
something like "connection reset by peer", "closed", "interrupted", "read  
error", "broken pipe", whatever. Active operations may complete, but  
responses can not be sent back.

If you do not close a transport client, the thread pool and socket  
connection pool will stay active and open unless you shut down the whole  
JVM.

A node client does not have a thread pool or connection pool, it is tied to  
the underlying node, and also in this case, unless you close the node, the  
node thread pool and node connection pool will stay open.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGSE%2B\_ZN8kra%3DAbVAFeVqYnwPpbcDJzQR9VCGVRUf21qg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGSE%2B_ZN8kra%3DAbVAFeVqYnwPpbcDJzQR9VCGVRUf21qg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Vasiliy\_S](https://avatars.discourse-cdn.com/v4/letter/v/91b2a8/32.png) [@Vasiliy\_S](https://discuss.elastic.co/u/Vasiliy_S)\
**Post date:** [December 3, 2013, 9:23am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/3 "2013-12-03T09:23:51Z")

</div>

Hi Jörg,

Thank you for your reply.  
Just to clarify I want to ask again. I'm using transport client on my  
client side. It's possible in my case that client JVM can be just turned  
off. Elasticsearch server is run on a different machine. Will there be some  
issues with elasticsearch (besides errors in logs) if I my client JVM is  
disabled by some reason?

Thanks,  
Vasiliy

On Tuesday, December 3, 2013 5:55:16 PM UTC+9, Jörg Prante wrote:

> If client is shutdown unexpectedly, there will be errors in the server  
> log, something like "connection reset by peer", "closed", "interrupted",  
> "read error", "broken pipe", whatever. Active operations may complete, but  
> responses can not be sent back.
> 
> If you do not close a transport client, the thread pool and socket  
> connection pool will stay active and open unless you shut down the whole  
> JVM.
> 
> A node client does not have a thread pool or connection pool, it is tied  
> to the underlying node, and also in this case, unless you close the node,  
> the node thread pool and node connection pool will stay open.
> 
> Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9b151bf4-6415-4136-9919-86872eaad16b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b151bf4-6415-4136-9919-86872eaad16b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [December 3, 2013, 9:47am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/4 "2013-12-03T09:47:24Z")

</div>

The issues are dropped connections, and maybe lost documents when indexing  
is active.

You were asking about memory leaks. This is only one type of bugs. There  
have been some Netty 3-related bugs a while ago, the epoll bug for example  
(\< 3.2.6)

It always depends on the versions, if there are known bugs or not.

This is one of the reasons why Netty 4 is not yet integrated into ES I  
guess. There is a certain risk of yet undiscovered resource leaks, such as  
[https://github.com/netty/netty/issues/1621](https://github.com/netty/netty/issues/1621) or  
[https://github.com/netty/netty/issues/1624](https://github.com/netty/netty/issues/1624)

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHTnhSdDV%2BJGof4Mnk127kwhihggOMMuaqqnH-1GkZ-Vg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHTnhSdDV%2BJGof4Mnk127kwhihggOMMuaqqnH-1GkZ-Vg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Vasiliy\_S](https://avatars.discourse-cdn.com/v4/letter/v/91b2a8/32.png) [@Vasiliy\_S](https://discuss.elastic.co/u/Vasiliy_S)\
**Post date:** [December 4, 2013, 1:24am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/5 "2013-12-04T01:24:18Z")

</div>

I see your point. Thank you for reply. It's better to try to close client  
in such a case.

Cheers,  
Vasiliy

On Tuesday, December 3, 2013 6:47:24 PM UTC+9, Jörg Prante wrote:

> The issues are dropped connections, and maybe lost documents when indexing  
> is active.
> 
> You were asking about memory leaks. This is only one type of bugs. There  
> have been some Netty 3-related bugs a while ago, the epoll bug for example  
> (\< 3.2.6)
> 
> It always depends on the versions, if there are known bugs or not.
> 
> This is one of the reasons why Netty 4 is not yet integrated into ES I  
> guess. There is a certain risk of yet undiscovered resource leaks, such as  
> [Resource Leak · Issue #1621 · netty/netty · GitHub](https://github.com/netty/netty/issues/1621) or  
> [Spurious "LEAK: ByteBuf was GC'd before being released correctly" message? · Issue #1624 · netty/netty · GitHub](https://github.com/netty/netty/issues/1624)
> 
> Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9fbc6907-4c7b-4abe-a862-f3fa47d54ff7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fbc6907-4c7b-4abe-a862-f3fa47d54ff7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:03am UTC](https://discuss.elastic.co/t/closing-client-on-shutdown/14669/6 "2017-07-06T02:03:30Z")

</div>


