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

Explicitly close the connection pool using at_exit #343

Merged
merged 1 commit into from
Apr 22, 2016
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ appear at the top.

* Add your entries below here, remember to credit yourself however you want
to be credited!
* SSHKit now explicitly closes its pooled SSH connections when Ruby exits;
this fixes `zlib(finalizer): the stream was freed prematurely` warnings
[PR #343](https://github.com/capistrano/sshkit/pull/343) @mattbrictson
* Allow command map entries (`SSHKit::CommandMap#[]`) to be Procs
[PR #310]((https://github.com/capistrano/sshkit/pull/310)
@mikz
Expand Down
6 changes: 6 additions & 0 deletions lib/sshkit/backends/netssh.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'English'
require 'net/ssh'
require 'net/scp'

Expand Down Expand Up @@ -44,7 +45,12 @@ def download!(remote, local=nil, options = {})
end
end

# Note that this pool must be explicitly closed before Ruby exits to
# ensure the underlying IO objects are properly cleaned up. We register an
# at_exit handler to do this automatically, as long as Ruby is exiting
# cleanly (i.e. without an exception).
@pool = SSHKit::Backend::ConnectionPool.new
at_exit { @pool.close_connections if @pool && !$ERROR_INFO }

class << self
attr_accessor :pool
Expand Down