Skip to content

Conversation

@tenderlove
Copy link
Collaborator

5bae22e introduced a memory leak when
it switched to connection pooling. We're setting a thread local but
then never clearing the local. If the pool is used in the main thread,
it will never die and the locals will stick around for the life of the
process.

Here is the program I used to test:

require 'net/http/persistent'

def run2
  1000.times do
    uri = URI 'http://localhost:5000'
    http = Net::HTTP::Persistent.new name: 'my_app_name'
    # perform a GET
    response = http.request uri
    # if you are done making http requests, or won't make requests for several
    # minutes
    http.shutdown
  end
end

p Thread.current.keys
run2
p Thread.current.keys

5bae22e introduced a memory leak when
it switched to connection pooling.  We're setting a thread local but
then never clearing the local.  If the pool is used in the main thread,
it will never die and the locals will stick around for the life of the
process.

Here is the program I used to test:

```
require 'net/http/persistent'

def run2
  1000.times do
    uri = URI 'http://localhost:5000'
    http = Net::HTTP::Persistent.new name: 'my_app_name'
    # perform a GET
    response = http.request uri
    # if you are done making http requests, or won't make requests for several
    # minutes
    http.shutdown
  end
end

p Thread.current.keys
run2
p Thread.current.keys
```
@tenderlove
Copy link
Collaborator Author

I think this fixes #96

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 this pull request may close these issues.

1 participant