Giter Site home page Giter Site logo

Comments (17)

edgurgel avatar edgurgel commented on May 3, 2024

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.

shankardevy avatar shankardevy commented on May 3, 2024

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&amp;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.

edgurgel avatar edgurgel commented on May 3, 2024

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.

jschniper avatar jschniper commented on May 3, 2024

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.

jschniper avatar jschniper commented on May 3, 2024

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.

edgurgel avatar edgurgel commented on May 3, 2024

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.

jschniper avatar jschniper commented on May 3, 2024

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.

jschniper avatar jschniper commented on May 3, 2024

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.

edgurgel avatar edgurgel commented on May 3, 2024

@jschniper, yeah go ahead! 👍

from httpoison.

jschniper avatar jschniper commented on May 3, 2024

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.

edgurgel avatar edgurgel commented on May 3, 2024

Can you share the hackney and HTTPoison versions that you are using? I want to investigate as well.

from httpoison.

jschniper avatar jschniper commented on May 3, 2024

I was using HTTPoison 0.8.0 which I think corresponds with hackney 1.4.8

from httpoison.

edevil avatar edevil commented on May 3, 2024

Any news on this?

from httpoison.

edgurgel avatar edgurgel commented on May 3, 2024

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.

jschniper avatar jschniper commented on May 3, 2024

I've had my fork in production for a few days and everything looks good.

from httpoison.

edgurgel avatar edgurgel commented on May 3, 2024

@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.

edgurgel avatar edgurgel commented on May 3, 2024

Released https://github.com/edgurgel/httpoison/releases/tag/v0.8.1

from httpoison.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.