elastic / go-elasticsearch

The official Go client for Elasticsearch
https://github.com/elastic/go-elasticsearch#go-elasticsearch
Apache License 2.0
5.54k stars 609 forks source link

Consider exposing a Close function on elasticsearch.Client #875

Open codefromthecrypt opened 3 weeks ago

codefromthecrypt commented 3 weeks ago

elasticsearch.Client should consider a Close function as its elastictransport.Client does a couple things, which at least for unit tests may be best to stop explicitly. We may also want to accept a context on New for similar reasons.

Starts the goroutine client.DiscoverNodes: This may want to be cancelable, e.g. passing a context to the New function. Agree this is not typical, but personally I pass ctx into New functions that perform I/O.

Via elastic-transport-go, starts a self-scheduling function for discovery: On Close, this should be stopped explicitly somehow, or documented why that's not required.

I didn't mention the edge case of http transport, that we have an opportunity to CloseIdleConnections, as I think above are more important to rule in or out.