Skip to content

Commit

Permalink
Explicitly close the connection pool using at_exit
Browse files Browse the repository at this point in the history
This fixes the `zlib(finalizer): the stream was freed prematurely` warning that
is printed by net-ssh when Ruby exits without closing the SSH connection first.
  • Loading branch information
mattbrictson committed Apr 22, 2016
1 parent 6a94cdc commit 77e9987
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 77e9987

Please sign in to comment.