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

Add Aws.empty_connection_pools! API #1451

Merged
merged 4 commits into from Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core.rb
Expand Up @@ -403,6 +403,21 @@ def use_bundled_cert!
))
end

# Close any long-lived connections maintained by the SDK's internal
# connection pool.
#
# Applications that rely heavily on the `fork()` system call on POSIX systems
# should call this method in the child process directly after fork to ensure
# there are no race conditions between the parent process and its children
# for the pooled TCP connections.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should expand this to note that the method should return before making client calls in the child process. In theory, a threaded system might call this, start API calls before we clear, and have issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated documentation in latest commit

#
# @return [nil]
def empty_connection_pools!
Seahorse::Client::NetHttp::ConnectionPool.pools.each do |pool|
pool.empty!
end
end

# Loads modules that are normally loaded with Ruby's `autoload`.
# This can avoid thread-safety issues that some Ruby versions have
# with `autoload`.
Expand Down
15 changes: 15 additions & 0 deletions aws-sdk-core/spec/aws_spec.rb
Expand Up @@ -138,4 +138,19 @@ module Aws
end

end

describe '.empty_connection_pools!' do
it 'closes any existing sessions' do
endpoint = "http://example.com"
conn_pool = Seahorse::Client::NetHttp::ConnectionPool.for({})
session = conn_pool.send(:start_session, endpoint)
conn_pool.instance_variable_get(:@pool)[endpoint] = [session]

expect(conn_pool.size).to eq(1)

Aws.empty_connection_pools!

expect(conn_pool.size).to eq(0)
end
end
end