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

Increase connection keep alive timeout to 30 seconds #836

Merged
merged 1 commit into from
Aug 20, 2019
Merged
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
11 changes: 9 additions & 2 deletions lib/stripe/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def connection_for(uri)

if connection.nil?
connection = create_connection(u)

# TODO: what happens after TTL?
connection.start

@active_connections[[u.host, u.port]] = connection
Expand Down Expand Up @@ -92,6 +90,15 @@ def execute_request(method, uri, body: nil, headers: nil, query: nil)
proxy_host, proxy_port,
proxy_user, proxy_pass)

# Time in seconds within which Net::HTTP will try to reuse an already
# open connection when issuing a new operation. Outside this window, Ruby
# will transparently close and re-open the connection without trying to
# reuse it.
#
# Ruby's default of 2 seconds is almost certainly too short. Here I've
# reused Go's default for `DefaultTransport`.
connection.keep_alive_timeout = 30

connection.open_timeout = Stripe.open_timeout
connection.read_timeout = Stripe.read_timeout

Expand Down