Skip to content

Commit 15251f1

Browse files
authored
Merge pull request #448 from tisba/gh-438
Fix Disabling of Connection Pool
2 parents ac18160 + 162cbfd commit 15251f1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ appear at the top.
66
## [Unreleased][]
77

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

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

lib/sshkit/backends/connection_pool.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def inspect
2121

2222
# The ConnectionPool caches connections and allows them to be reused, so long as
2323
# the reuse happens within the `idle_timeout` period. Timed out connections are
24-
# closed, forcing a new connection to be used in that case.
24+
# eventually closed, forcing a new connection to be used in that case.
2525
#
2626
# Additionally, a background thread is started to check for abandoned
2727
# connections that have timed out without any attempt at being reused. These
@@ -46,7 +46,11 @@ def initialize(idle_timeout=30)
4646
@caches = {}
4747
@caches.extend(MonitorMixin)
4848
@timed_out_connections = Queue.new
49-
Thread.new { run_eviction_loop }
49+
50+
# Spin up eviction loop only if caching is enabled
51+
if cache_enabled?
52+
Thread.new { run_eviction_loop }
53+
end
5054
end
5155

5256
# Creates a new connection or reuses a cached connection (if possible) and
@@ -133,7 +137,7 @@ def run_eviction_loop
133137
process_deferred_close
134138

135139
# Periodically sweep all Caches to evict stale connections
136-
sleep([idle_timeout, 5].min)
140+
sleep(5)
137141
caches.values.each(&:evict)
138142
end
139143
end

0 commit comments

Comments
 (0)