lbry-sdk icon indicating copy to clipboard operation
lbry-sdk copied to clipboard

Connection to ElasticSearch running inside Docker fails (MacOS)

Open moodyjon opened this issue 3 years ago • 0 comments

I am running lbry-sdk integration tests locally on MacOS, with elastic-search inside Docker. I used the lbry-sdk/Makefile command to launch it:

elastic-docker:
	docker run -d -v lbryhub:/usr/share/elasticsearch/data -p 9200:9200 -p 9300:9300 -e"ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.12.1

In order to connect herald -> elastic-search, I had to disable the SetSniff() option.

diff --git a/server/server.go b/server/server.go
index 415b728..7706e72 100644
--- a/server/server.go
+++ b/server/server.go
@@ -210,7 +210,7 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
        if !args.DisableEs {
                esUrl := args.EsHost + ":" + args.EsPort
                opts := []elastic.ClientOptionFunc{
-                       elastic.SetSniff(true),
+                       elastic.SetSniff(false),
                        elastic.SetSnifferTimeoutStartup(time.Second * 60),
                        elastic.SetSnifferTimeout(time.Second * 60),
                        elastic.SetURL(esUrl),

Probably the clearest explanation: https://github.com/olivere/elastic/issues/1138

More similar issues: https://github.com/olivere/elastic/issues?q=is%3Aissue+docker+SetSniff+SetHealthCheck

Making a --nosniff option MAY NOT be the best solution here. I found the following comment describes how to fix this using the network.publish_host option of ElasticSearch. https://github.com/olivere/elastic/issues/824#issuecomment-474416267

Example: docker run --env network.publish_host=127.0.0.1 ...

I tested "--env network.publish_host=127.0.0.1" and it worked for me.

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html#advanced-network-settings

Symbolic addresses like network.publish_host=_local_ are supported.

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html#network-interface-values

moodyjon avatar Jul 29 '22 20:07 moodyjon