Elasticsearch-js: no living connections

Created on 24 Apr 2014  路  9Comments  路  Source: elastic/elasticsearch-js

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'http://id:pwd@host:port/',
log: 'trace',
});

client.search({
    index: 'index',
    type: 'type',
    body:{
        query:{
            match:{
                body:'timeout'
            }
        }
    }
}).then(function (resp) {
    var hits = resp.hits.hits;
    console.log("matching cases:"+resp.hits.hits.length);
}, function (err) {
    console.trace(err.message);
});

I was trying to test elasticsearch module with code above, and it worked at first but after trying several times, I got following error message.

Elasticsearch ERROR: 2014-04-24T02:55:19Z
Error: Request error, retrying -- connect ECONNREFUSED
at Log.error (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\src\lib\log.js:213:60)
at checkRespForFailure (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\src\lib\transport.js:187:18)
at HttpConnector.<anonymous> (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\src\lib\connectors\http.js:145:7)
at ClientRequest.bound (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\lodash-node\modern\internals\baseBind.js:56:17)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)

Elasticsearch WARNING: 2014-04-24T02:55:19Z
Unable to revive connection: http://id:pwd@host:port/

    Elasticsearch WARNING: 2014-04-24T02:55:19Z
No living connections

Trace: No Living connections
at C:\Users\Administrator\IdeaProjects\empty\nodejstest\test.js:54:13
at tryCatch1 (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\util.js:63:19)
at Promise$_callHandler [as _callHandler] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\promise.js:695:13)
at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\promise.js:711:18)
at Promise$_settlePromiseAt [as _settlePromiseAt] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\promise.js:868:14)
at Promise$_settlePromises [as _settlePromises] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\promise.js:1006:14)
at Promise$_rejectPromises [as _rejectPromises] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\promise.js:999:10)
at Async$_consumeFunctionBuffer [as _consumeFunctionBuffer] (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\async.js:74:12)
at Async$consumeFunctionBuffer (C:\Users\Administrator\IdeaProjects\empty\nodejstest\node_modules\elasticsearch\node_modules\bluebird\js\main\async.js:37:14)
at process._tickCallback (node.js:415:13)

It never revives and also I cannot connect to my elasticsearch cluster through web browser with url "http://ip:port/_search" or something similar.

I think there maybe a problem with releasing connection, is there a solution?

Would be great if you can tell me how to restore elasticsearch in this situation without restarting process itself.

Most helpful comment

The problem in my case is that I can't close the connection. I keep the connection for long because I have a crawler that persists to elastic. What should I do in that case?

All 9 comments

If you kill the node process, the connections won't be open any more and you should be able to access elasticsearch (assuming that is the issue).

Can you see elasticsearch's logs? Anything suspicious there?

What do you think is the best way to manage connections, can I use generic-pool module with this?
I don't see method named elasticsearch.close() or quit() or whatever.

I'll look into ES logs btw.

Meant to comment here previously, elasticsearch.js has a pretty good connection pool built in, and client instances do have a client.close() method you can use.

Hi all,

I came across the same error recently and wanted to share my observations.

I created the client with:
var client = new elasticsearch.Client({ host: 'localhost:9200', log: 'trace' });

...and then did requests on an interval of 1 second. After some time, I always got "Error: Request error, retrying -- connect ECONNREFUSED".

I checked ES server with curl ping and it was always reachable.

I changed the host to IP (127.0.0.1:9200) instead and got a different error: "Request error, retrying -- connect EMFILE" which is a nodejs error which, according to SO answer, "means that the OS is denying your program to open more files/sockets" (http://stackoverflow.com/questions/10355501/connect-emfile-error-in-node-js).

I then realised I never closed/released the client connection but always created a new one instead of re-using the existing client.

Not sure if this is actually a problem on elasticsearch-js side as to me it seems this problem arises from misusing the module. Hope this helps to narrow down the bug or someone stumbling here in the future.

Thanks for the info @haadcode

Hi.

So, the solution could be close every connection after using it?

The problem in my case is that I can't close the connection. I keep the connection for long because I have a crawler that persists to elastic. What should I do in that case?

hi just download elastic search from its official site.Then extract the file and then go to bin file.Run the
elastic search.bat file with cmd and go to localhost:9200 on your browser .The problem is resolved

Hi all,

I came across the same error recently and wanted to share my observations.

I created the client with:
var client = new elasticsearch.Client({ host: 'localhost:9200', log: 'trace' });

...and then did requests on an interval of 1 second. After some time, I always got "Error: Request error, retrying -- connect ECONNREFUSED".

I checked ES server with curl ping and it was always reachable.

I changed the host to IP (127.0.0.1:9200) instead and got a different error: "Request error, retrying -- connect EMFILE" which is a nodejs error which, according to SO answer, "means that the OS is denying your program to open more files/sockets" (http://stackoverflow.com/questions/10355501/connect-emfile-error-in-node-js).

I then realised I never closed/released the client connection but always created a new one instead of re-using the existing client.

Not sure if this is actually a problem on elasticsearch-js side as to me it seems this problem arises from misusing the module. Hope this helps to narrow down the bug or someone stumbling here in the future.

try to keep log:'error' instead of 'trace',you wont see warning,

Was this page helpful?
0 / 5 - 0 ratings