Node.js client and ECONNRESET

(Pepa Štefan) #1

Hi, I'm trying to query elasticsearch from node.js and from time to time I get error

[Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read'.

The queries goes one after other, quite quickly, one query takes maybe 30ms to resolve.
Typical query is this one:

POST http://localhost:10200/cloudlog/raw/_search HTTP/1.1
host: localhost:10200
accept: application/json
content-type: application/json
content-length: 109
Connection: close


What changes is the BatchId.


HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 16721


What's strange is that fiddler shows me no problem with the request and response. What does that error mean?

Node js. source code for calling elasticsearch (using request npm module):

function FindByQuery_promise(query) {
  var deferred = Q.defer();
  var r = request({
      url: this._documentUrl + "/_search",
      method: "POST",
      json: true,
      body: query
  }, function(e, response, body) {
    body = body || { error: null };
    if (e || body.error) {
      console.error("Error", e, body.error);
      deferred.reject(new Error(e || body.error));
    } else {
  return deferred.promise;

Any help would be approciated as I don't know when coding whether the response is valid or not. And also sometimes there is no error in dozens of thousands requests and then there are request errors after some hundreds requests...

(Pepa Štefan) #2

Maybe it's really related to Node.js, because it keeps a lot of tcp connections in fin_wait2 state. When I ran Process Monitor and watched node, there were about 40 connections that were disconnected when node exited.

When loooking through Process Explorer, the node is connecting to ES, then the connections are in fin_wait2 for some time and then disconnected.
Maybe lowering limit of connections in fin_wait2 would help..

(system) #3