drbrain / net-http-persistent

Thread-safe persistent connections with Net::HTTP
http://seattlerb.rubyforge.org/net-http-persistent
339 stars 117 forks source link

Clear thread data in the "checkin" method to fix memory leak #105

Closed ykitamura-mdsol closed 5 years ago

ykitamura-mdsol commented 5 years ago

Still leaking memory when using with Faraday. Since the shutdown method added in https://github.com/drbrain/net-http-persistent/pull/98 cannot be called from the Faraday adapter, empty arrays remain in the main thread after making requests:

Thread.current.keys
#=> [.., :"current-70179311374800", ..]
Thread.current[:"current-70179311374800"]
#=> {["example.org", 443]=>[]}

In the connection_pool gem, thread data is set to nil in the checkin method:

  def checkin
    if ::Thread.current[@key]
      if ::Thread.current[@key_count] == 1
        @available.push(::Thread.current[@key])
        ::Thread.current[@key]= nil
      else
        ::Thread.current[@key_count]-= 1
      end
    else
      raise ConnectionPool::Error, 'no connections are checked out'
    end

    nil
  end

This PR is following the logic to clear thread data in the checkin method.

@tenderlove It seems the change bumping the version to 3.0.1 is not merged into the master branch. How should I bump the version?

@jcarres-mdsol @jfeltesse-mdsol @cabbott @ssteeg-mdsol @piao-mdsol