Elasticsearch-js: Error: Request error, retrying -- connect ECONNREFUSED 127.0.0.1:9200

Created on 7 Jan 2016  路  10Comments  路  Source: elastic/elasticsearch-js

Hi guys, i'm hitting this over & over again.

 Elasticsearch ERROR: 2016-01-07T21:20:52Z
  Error: Request error, retrying -- connect ECONNREFUSED 127.0.0.1:9200
      at Log.error (/usr/src/project/node_modules/elasticsearch/src/lib/log.js:225:56)
      at checkRespForFailure (/usr/src/project/node_modules/elasticsearch/src/lib/transport.js:231:18)
      at HttpConnector.<anonymous> (/usr/src/project/node_modules/elasticsearch/src/lib/connectors/http.js:153:7)
      at ClientRequest.wrapper (/usr/src/project/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19)
      at emitOne (events.js:77:13)
      at ClientRequest.emit (events.js:169:7)
      at Socket.socketErrorListener (_http_client.js:259:9)
      at emitOne (events.js:77:13)
      at Socket.emit (events.js:169:7)
      at emitErrorNT (net.js:1253:8)

Elasticsearch WARNING: 2016-01-07T21:20:52Z
  Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2016-01-07T21:20:52Z
  No living connections

Error: No Living connections
    at sendReqWithConnection (/usr/src/project/node_modules/elasticsearch/src/lib/transport.js:210:15)
    at next (/usr/src/project/node_modules/elasticsearch/src/lib/connection_pool.js:213:7)
    at doNTCallback0 (node.js:419:9)
    at process._tickCallback (node.js:348:13)

The situation is like this. I have a nodejs app running inside a docker container.
Inside this app, I've create the client like this

var client = new elasticsearch.Client({
        connectionClass: CustomESHTTPConnector,
        host: process.env.ELASTICSEARCH_HOST,
        deadTimeout: 100000,
        maxRetries: 6
    });

Where ELASTICSEARCH_HOST is the address of another VM inside the same network => 10.0.0.5 running ES, of course

If I curl 10.0.0.5:9200 inside the container, and inside the VM hosting that container, I get

{
  "name" : "app-node",
  "cluster_name" : "app-cluster",
  "version" : {
    "number" : "2.1.1",
    "build_hash" : "40e2c53a6b6c2972b3d13846e450e66f4375bd71",
    "build_timestamp" : "2015-12-15T13:05:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

The app shoud reach the elasticsearch server. Any ideas why im getting this? Thanks in advance

Most helpful comment

Closing this.

The error was the process.env.ELASTICSEARCH_HOST not being set at the runtime for another reason. Thaks for your help @iquirino & @spalger !

All 10 comments

Is this happening on the first request or only after some time?

Yes, on the first request. When trying to create the index. On the elasticsearch logs I'cant see any connection. It seems like its not reaching the server at all

Maybe elasticsearch isn't listening on 127.0.0.1? ECONNREFUSED is from the network stack, well outside the realm of the client unfortunately

Right, I'm using the config network.host: 0.0.0.0 on ES (otherwise I can't reach ES from the outside of the VM).

Can this be the problem?

Change network.host: 0.0.0.0 to network.host: "localhost"

Are you using NAT or Bridge?
If using NAT, dont forget to explicitly specify port redirection.

VMWare, Oracle VirtualBox ??

Thank you!

@iquirino I did that, but the problem is that curl 10.0.0.5:9200 from the outside of the VM gives me curl: (7) Failed to connect to 10.0.0.5 port 9200: Connection refused

Im using Azure

UPDATE: Im still having the exact same issue even when running network.host: "localhost"

Closing this.

The error was the process.env.ELASTICSEARCH_HOST not being set at the runtime for another reason. Thaks for your help @iquirino & @spalger !

Plz help . how can i fix it? :(

$ node initdata
Elasticsearch INFO: 2017-01-11T03:19:19Z
  Adding connection to http://localhost:9200/

Elasticsearch DEBUG: 2017-01-11T03:19:19Z
  starting request {
    "method": "HEAD",
    "requestTimeout": 5000,
    "castExists": true,
    "path": "/",
    "query": {}
  }


Elasticsearch DEBUG: 2017-01-11T03:19:19Z
  starting request {
    "method": "PUT",
    "path": "/chesshub",
    "query": {}
  }


(node:7088) DeprecationWarning: Mongoose: mpromise (mongoose's default promise l
ibrary) is deprecated, plug in your own promise library instead: http://mongoose
js.com/docs/promises.html
Elasticsearch TRACE: 2017-01-11T03:19:20Z
  -> HEAD http://localhost:9200/

  <- 0


Elasticsearch ERROR: 2017-01-11T03:19:20Z
  Error: Request error, retrying
  HEAD http://localhost:9200/ => connect ECONNREFUSED 127.0.0.1:9200
      at Log.error (C:\Users\MyPC\Desktop\gamehub.io-master\node_modules\elastic
search\src\lib\log.js:225:56)
      at checkRespForFailure (C:\Users\MyPC\Desktop\gamehub.io-master\node_modul
es\elasticsearch\src\lib\transport.js:240:18)
      at HttpConnector.<anonymous> (C:\Users\MyPC\Desktop\gamehub.io-master\node
_modules\elasticsearch\src\lib\connectors\http.js:162:7)
      at ClientRequest.wrapper (C:\Users\MyPC\Desktop\gamehub.io-master\node_mod
ules\elasticsearch\node_modules\lodash\lodash.js:4968:19)
      at emitOne (events.js:96:13)
      at ClientRequest.emit (events.js:188:7)
      at Socket.socketErrorListener (_http_client.js:309:9)
      at emitOne (events.js:96:13)
      at Socket.emit (events.js:188:7)
      at emitErrorNT (net.js:1281:8)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)

Elasticsearch TRACE: 2017-01-11T03:19:20Z
  -> PUT http://localhost:9200/chesshub

  <- 0


Elasticsearch ERROR: 2017-01-11T03:19:20Z
  Error: Request error, retrying
  PUT http://localhost:9200/chesshub => connect ECONNREFUSED 127.0.0.1:9200
      at Log.error (C:\Users\MyPC\Desktop\gamehub.io-master\node_modules\elastic
search\src\lib\log.js:225:56)
      at checkRespForFailure (C:\Users\MyPC\Desktop\gamehub.io-master\node_modul
es\elasticsearch\src\lib\transport.js:240:18)
      at HttpConnector.<anonymous> (C:\Users\MyPC\Desktop\gamehub.io-master\node
_modules\elasticsearch\src\lib\connectors\http.js:162:7)
      at ClientRequest.wrapper (C:\Users\MyPC\Desktop\gamehub.io-master\node_mod
ules\elasticsearch\node_modules\lodash\lodash.js:4968:19)
      at emitOne (events.js:96:13)
      at ClientRequest.emit (events.js:188:7)
      at Socket.socketErrorListener (_http_client.js:309:9)
      at emitOne (events.js:96:13)
      at Socket.emit (events.js:188:7)
      at emitErrorNT (net.js:1281:8)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)

Elasticsearch TRACE: 2017-01-11T03:19:21Z
  -> HEAD http://localhost:9200/

  <- 0


Elasticsearch WARNING: 2017-01-11T03:19:21Z
  Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:21Z
  No living connections

elasticsearch is down!
Elasticsearch TRACE: 2017-01-11T03:19:21Z
  -> HEAD http://localhost:9200/

  <- 0


Elasticsearch WARNING: 2017-01-11T03:19:21Z
  Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:21Z
  No living connections

Elasticsearch DEBUG: 2017-01-11T03:19:21Z
  starting request {
    "method": "POST",
    "path": "/chesshub/game/1/_create",
    "body": {
      "white": "Foo",
      "black": "Anonymous",
      "content": "1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. O-O Bc5 5. c3 O-O 6. d4 exd4
 7. cxd4 Bb4",
      "result": "1-0"
    },
    "query": {}
  }


Elasticsearch TRACE: 2017-01-11T03:19:22Z
  -> HEAD http://localhost:9200/

  <- 0


Elasticsearch WARNING: 2017-01-11T03:19:22Z
  Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:22Z
  No living connections

Elasticsearch DEBUG: 2017-01-11T03:19:23Z
  starting request {
    "method": "POST",
    "path": "/chesshub/game/2/_create",
    "body": {
      "white": "Anonymous",
      "black": "Bar",
      "content": "1. e4 c6 2. e5 d5 3. exd6 exd6 4. Nf3 Bg4 5. d4 Nf6 6. Bg5 Be7
",
      "result": "1-0"
    },
    "query": {}
  }

@Cuong12 Please put your log output inside well-indented code-blocks so that's more readable, thank you.

@Cuong12 - Locate the 'elasticsearch.js' file on your system, then change the variable this.host = 'localhost' to this.host = '0.0.0.0'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msisti picture msisti  路  32Comments

milu2003 picture milu2003  路  17Comments

coldlamper picture coldlamper  路  12Comments

Remexllee picture Remexllee  路  9Comments

carsotho picture carsotho  路  20Comments