Skip to content

Commit

Permalink
Merge pull request #448 from tisba/gh-438
Browse files Browse the repository at this point in the history
Fix Disabling of Connection Pool
  • Loading branch information
leehambley authored Jan 30, 2019
2 parents ac18160 + 162cbfd commit 15251f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ appear at the top.
## [Unreleased][]

* Your contribution here!
* [#448](https://github.com/capistrano/sshkit/pull/448): Fix misbehaving connection eviction loop when disabling connection pooling - [Sebastian Cohnen](https://github.com/tisba)

## [1.18.1][] (2019-01-26)

Expand Down
10 changes: 7 additions & 3 deletions lib/sshkit/backends/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def inspect

# The ConnectionPool caches connections and allows them to be reused, so long as
# the reuse happens within the `idle_timeout` period. Timed out connections are
# closed, forcing a new connection to be used in that case.
# eventually closed, forcing a new connection to be used in that case.
#
# Additionally, a background thread is started to check for abandoned
# connections that have timed out without any attempt at being reused. These
Expand All @@ -46,7 +46,11 @@ def initialize(idle_timeout=30)
@caches = {}
@caches.extend(MonitorMixin)
@timed_out_connections = Queue.new
Thread.new { run_eviction_loop }

# Spin up eviction loop only if caching is enabled
if cache_enabled?
Thread.new { run_eviction_loop }
end
end

# Creates a new connection or reuses a cached connection (if possible) and
Expand Down Expand Up @@ -133,7 +137,7 @@ def run_eviction_loop
process_deferred_close

# Periodically sweep all Caches to evict stale connections
sleep([idle_timeout, 5].min)
sleep(5)
caches.values.each(&:evict)
end
end
Expand Down

0 comments on commit 15251f1

Please sign in to comment.