Skip to content

Commit e2540af

Browse files
binarycodeioquatix
authored andcommitted
fix leaking sockets
1 parent c9e957d commit e2540af

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/async/http/faraday/adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def call(env)
3636
save_response(env, response.status, response.read, response.headers)
3737

3838
@app.call env
39+
ensure
40+
client.close if client
3941
end
4042

4143
def endpoints_for(env)

spec/async/http/faraday/adapter_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,24 @@ def get_response(url, path)
8686
expect(response.body).to be_nil
8787
end
8888
end
89+
90+
if RbConfig::CONFIG['host_os'] =~ /linux/
91+
it 'does not leak sockets' do
92+
def get_socket_count
93+
`ls -l /proc/#{$$}/fd | grep socket | wc -l`.to_i
94+
end
95+
96+
REQUEST_COUNT = 100
97+
98+
run_server(Protocol::HTTP::Response[204]) do
99+
sockets_before = get_socket_count
100+
101+
REQUEST_COUNT.times { get_response(endpoint.url, '/index') }
102+
103+
sockets_after = get_socket_count
104+
105+
expect(sockets_after - sockets_before).to be < REQUEST_COUNT
106+
end
107+
end
108+
end
89109
end

0 commit comments

Comments
 (0)