Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I call Net::HTTP::Persistent.shutdown? #19

Open
sudoudaisuke opened this issue Apr 10, 2024 · 1 comment
Open

How do I call Net::HTTP::Persistent.shutdown? #19

sudoudaisuke opened this issue Apr 10, 2024 · 1 comment

Comments

@sudoudaisuke
Copy link

sudoudaisuke commented Apr 10, 2024

Hello. I want to reuse a Net::HTTP connection. However, I want to destroy (close) the connection after one sequence operation.

sample code

conn = Faraday.new do |f|
    f.adapter :net_http_persistent, pool_size: 5 do |http|
        http.idle_timeout = 5
    end
end
conn.get('http://example.com/1')
conn.get('http://example.com/2') # reuse connection
conn.get('http://example.com/3') # reuse connection, end of sequence

conn.close # I want to destroy connection pool

# create new connection pool
conn = Faraday.new do |f|
    f.adapter :net_http_persistent, pool_size: 5 do |http|
        http.idle_timeout = 5
    end
end
conn.get('http://example.com/1')
conn.get('http://example.com/2') # reuse connection
conn.get('http://example.com/3') # reuse connection, end of sequence

conn.close # I want to destroy connection pool

I think the conn.close method is just calling Faraday::Adapter::NetHttpPersistent.close. And Faraday::Adapter::NetHttpPersistent.close is not implemented.

I think calling @cached_connection.shutdown is destory connections, Like this.

conn.app.instance_variable_get(:@cached_connection).shutdown

Is there an easier way to destory a connection? Or is it a process that does not require destroying the connection?

@sudoudaisuke sudoudaisuke changed the title How do I call Net::HTTP::Persistent.shutdow? How do I call Net::HTTP::Persistent.shutdown? Apr 10, 2024
@olleolleolle
Copy link
Member

@sudoudaisuke Thank you for asking, I made the smallest implementation of #23, would you try that and see if it fits your needs?

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

No branches or pull requests

2 participants