Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/async/http/faraday/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ def with_proxied_client(proxy_endpoint, endpoint, &block)
# This will close all clients associated with all threads.
def close
Thread.list.each do |thread|
if clients = thread[@key]
clients.close
if clients = thread.thread_variable_get(@key)
thread.thread_variable_set(@key, nil)

thread[@key] = nil
clients.close
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Fix memory leak in `Async::HTTP::Faraday::PerThreadPersistentClients` by ensuring that the `close` method is called on all clients when the adapter is closed.

## v0.21.0

### Improved support for `timeout` and `read_timeout`.
Expand Down
29 changes: 29 additions & 0 deletions test/async/http/faraday/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,33 @@
end
end
end

with "#close" do
it "closes all clients" do
endpoint = Async::HTTP::Endpoint.parse("http://example.com")
client = clients.make_client(endpoint)
expect(client).to receive(:close)

clients.close
end
end
end

describe Async::HTTP::Faraday::PerThreadPersistentClients do
let(:clients) {subject.new}

with "#close" do
it "closes all clients" do
endpoint = Async::HTTP::Endpoint.parse("http://example.com")
closed = false

clients.with_client(endpoint) do |client|
expect(client).to receive(:close, &proc{closed = true})
end

expect(closed).to be == false
clients.close
expect(closed).to be == true
end
end
end
Loading