4

I'm new to this. I'm working with ElasticClient (.Net) and I was curious if:

  1. Is it thread safe? I assume so because it uses pooling.
  2. Should I do anything to clean up the client resources when I'm done? It does not implement IDisposable.

Thanks!

Bob

Stolidedog
  • 41
  • 1
  • 2

1 Answers1

3

On thread safety: https://github.com/elastic/elasticsearch-net/issues/23

The ElasticClient holds a single IConnection responsible for doing async and sync http calls. The IConnection does not reuse httprequests and uses thread local state for data thats being passed around during the stages of the request. It should thus be thread safe.

On disposing: https://github.com/elastic/elasticsearch-net/issues/101

ElasticClient is almost stateless except for a static CLR type info cache that is threadsafe so you can even use one client over threads. Disposing is also handled by Nest and ElasticClient only exposes POCO's.

gsk
  • 1,233
  • 15
  • 32
  • 1
    If for some reason you need to create several clients for a short time, the absence of Dispose or at least close connection is becoming a problem as you can run out of resources really fast and you have no control on the lifetime of the connection. – user2555515 Apr 10 '17 at 00:27