Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set http.agent to false #327

Closed
jochenonline opened this issue Jan 4, 2016 · 7 comments
Closed

set http.agent to false #327

jochenonline opened this issue Jan 4, 2016 · 7 comments

Comments

@jochenonline
Copy link

Due to this issue it is necessary to have the possibility to set the http.agent to false. While doing a bulk insert into elastic I get no living connections available aka EADDRNOTAVAIL.

@spalger
Copy link
Contributor

spalger commented Jan 4, 2016

Okay, so I read through the linked issue and found this from nodejs/node-v0.x-archive#4769 (the source issue).

With an Agent configured for {keepAlive:false}, it will reuse connections only if there is a backlog (so it may actually use "Connection: keep-alive" under load; probably best to think of {keepAlive:false} more like forcing {maxFreeSockets:0} than anything else).

and

if you request with {agent:false} your request gets a new single-use agent instance w/defaults; i.e. it has the {keepAlive:false} behavior of the first bullet point above but is also guaranteed not to be reused since only the one request will ever be in its backlog.

I'm not sure how this is supposed to solve the issue you are experiencing; you will still run out of file descriptors eventually by setting agent: false since nothing is queued

@jochenonline
Copy link
Author

Setting agent: false does solve the problem! This has been the case with the nodejs-only example in the linked issue and is of course the same when doing bulk inserts in elasticsearch, because this is the same setup: at the end there are also many (many!) http requests from nodejs against an http-server.

So this is not a theoretical problem with a theoretical solution, but a really existing problem with a approved solution. The nodejs guys say the same, but unfortunately they have not fixed the problem corretcly after two years.

@spalger
Copy link
Contributor

spalger commented Jan 5, 2016

Can you link to a comment where someone says that agent: false solves the problem? I have seen your results but as the first comment mentions that is probably just slowing down the problem (since there isn't any queuing).

@jochenonline
Copy link
Author

So here you are right. From that perspective it probably does not solve the problem, but at least solves the symptom. So the question is, if you will allow the API-user to decide, wether to set the agent to null or not. In the latter case I have to use our fork.

@jochenonline
Copy link
Author

Your Solr equivalent did that.

@spalger
Copy link
Contributor

spalger commented Jan 5, 2016

I originally planned to refer you to this gist which I have pointed to several times in the past when users wanted to modify the node.js agent.

Rather than just doing that though, I submitted #329 which will allow you full control over the Agent that each http(s) backed connection will use. In order to accomplish your goal you would simply do:

var client = new elasticsearch.Client({
  createNodeAgent() {
    return false
  } 
})

Would you mind giving the PR a look and seeing if it works for you?

@jochenonline
Copy link
Author

Works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants