Comments (17)
HTTPoison fetches the body on every "sync" request:
https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L400-L404
I'm not sure what's the cause of the system limit but I can try to replicate on my machine. Can you share the httpoison and hackney version you are using?
from httpoison.
Pls see my updated comment here benoitc/hackney#257 (comment)
iex(56)> :erlang.system_info(:port_count)
11
iex(57)> HTTPoison.get "http://www.google.com"
{:ok,
%HTTPoison.Response{body: "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.co.in/?gfe_rd=cr&ei=2jVEVsWwKaTv8weynIGQDA\">here</A>.\r\n</BODY></HTML>\r\n",
headers: [{"Cache-Control", "private"},
{"Content-Type", "text/html; charset=UTF-8"},
{"Location", "http://www.google.co.in/?gfe_rd=cr&ei=2jVEVsWwKaTv8weynIGQDA"},
{"Content-Length", "261"}, {"Date", "Thu, 12 Nov 2015 06:46:50 GMT"},
{"Server", "GFE/2.0"}], status_code: 302}}
iex(58)> :erlang.system_info(:port_count)
12
iex(59)> :erlang.system_info(:port_count)
12
After about 2mins
iex(60)> :erlang.system_info(:port_count)
11
The delay of 2 mins to free up an used port increases the port count exponentially in my case and hits the limit causing system_limit error. Any ideas how to resolve it?
from httpoison.
I suspect that this is caused because hackney holds connections for some time and reuse if the request is going for the same host. I imagine you are doing request for different hosts and it's opening too many connections? Can you try to tweak the timeout
env that hackney uses?
https://github.com/benoitc/hackney/blob/master/src/hackney.app.src#L20
By default it's 150000
.
Application.put_env(:hackney, :timeout, 10000)
After 10 seconds the created port will get released.
from httpoison.
I'm running into a similar problem. I've been seeing a hackney pool where the in_use count slowly grows over time until it completely fills, which causes the application to become unresponsive. Something seems to be causing the sockets to hang open. I've been trying to track it back down to the individual requests to see if there is any commonality but I haven't had much luck yet. For some extra background, we're using HTTPoison inside a Phoenix application to pull data from a web service.
Hopefully I'll have some more information soon.
from httpoison.
I went back and set up a separate pool for each request so I could see if there were any particular ones that were problematic and it turns out there is one particular call that seems to be the culprit. I've included a simplified version of the code below.
def profile(token) do
pid = :poolboy.checkout(:redis_pool)
case :eredis.q(pid, ["GET", "profile:#{token}"], 5000) do
{:ok, :undefined} ->
resp = Service.get!("/profile/#{token}", ["Content-Type": "text/plain"], hackney: [pool: :profile])
:eredis.q(pid, ["SET", "profile:#{token}", Poison.encode!(resp.body), "EX", 900], 5000)
profile = resp.body
{:ok, profile} ->
profile = Poison.decode!(profile)
end
:poolboy.checkin(:redis_pool, pid)
profile
end
defmodule Service do
use HTTPoison.Base
def process_url(url) do
"http://example.com" <> url
end
def process_request_headers(headers) do
["Content-Type": "application/json", "Accept": "application/json"] ++ headers
end
def process_response_body(body) do
case Poison.decode(body) do
{:ok, json} -> json
_ -> body
end
end
end
from httpoison.
Just out of curiosity, what's the size of the redis_pool
? I imagine the size of the redis pool will be also the amount of simultaneous requests being done through HTTPoison/hackney. The amount of connections should at least the size of the redis_pool and I would also keep the time out limits similar so they both "give up" properly.
from httpoison.
The redis pool is sitting at 10 or 15 right now versus the 50 default max_connections for hackney but I'm not seeing any signs of too many requests. The behavior seems to be that we "lose" a socket every so often.
from httpoison.
I haven't had much time to circle back to this but I was wondering if you would recommend opening an issue in the hackney project?
from httpoison.
@jschniper, yeah go ahead! 👍
from httpoison.
I wanted to let you know that I replaced the call to HTTPoison with a call directly to hackney and I'm not seeing the sockets hanging open anymore. I went back and I noticed that the call I was making will either return a profile or a 204 if the profile can't be found so I was wondering if https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L397 might be the culprit.
I need to let the application run for a while longer to make sure the problem doesn't reappear but it certainly looks better at this moment.
from httpoison.
Can you share the hackney and HTTPoison versions that you are using? I want to investigate as well.
from httpoison.
I was using HTTPoison 0.8.0 which I think corresponds with hackney 1.4.8
from httpoison.
Any news on this?
from httpoison.
Related: #114
Can you guys give a try on HTTPoison master branch? If we are sure that this fixes our problem I can release a new version.
from httpoison.
I've had my fork in production for a few days and everything looks good.
from httpoison.
@jschniper oh ok! I thought you had just used directly hackney in production. That's great. I will release later today a bugfix version! Thank you for catching this bug 👍
from httpoison.
Released https://github.com/edgurgel/httpoison/releases/tag/v0.8.1
from httpoison.
Related Issues (20)
- Response HOT 2
- Request is getting closed. HOT 2
- HTTPoison.MaybeRedirect for 308 status_code ? HOT 11
- why no_proxy doesn't support CIDR range format?
- checkout_failure when using httpoison with proxy HOT 3
- Lowercase location header not recognized when constructing %HTTPoison.MaybeRedirect{}
- TLS client: In state wait_cert_cr at ssl_handshake.erl:1984 generated CLIENT ALERT: Fatal - Unknown CA HOT 3
- SSL options replace default options (instead of just being added to them) HOT 2
- Default TLS version? HOT 2
- Proxy option not working HOT 1
- Hackney 1.18? HOT 1
- Overly loose typespecs
- HTTPoison.get! follow_redirect does not work with an async request HOT 1
- Nested form-encoded params don't work HOT 2
- "Path not supported by Algolia REST API" HOT 2
- How to contribute HOT 1
- ipv6 localhost address is passed to hackney without square brackets HOT 1
- Get HTTPoison.Error{reason: {:options, :dependency}} when send request with settings for tlsv1.3
- Issue Case clause error
- Multipart content based post failing if the file name contains space or () characters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpoison.