-
Notifications
You must be signed in to change notification settings - Fork 255
Description
I recently noticed that our sidekiq is running at 100% CPU (see sidekiq/sidekiq#3918). We are using sshkit in our sidekiq workers.
We were using:
SSHKit::Backend::Netssh.pool.idle_timeout = 0Which causes a busy loop in ConnectionPool#run_eviction_loop as [idle_timeout, 5].min will be 0:
sshkit/lib/sshkit/backends/connection_pool.rb
Lines 131 to 139 in 70d01df
| def run_eviction_loop | |
| loop do | |
| process_deferred_close | |
| # Periodically sweep all Caches to evict stale connections | |
| sleep([idle_timeout, 5].min) | |
| caches.values.each(&:evict) | |
| end | |
| end |
Also, according to ConnectionPools documentation, idle_timeout can also be false or nil which will actually cause an exception ([nil, 5].min will raise).
I'm happy to propose a fix, but I'd like to have guidance how. My proposal would be to impose a lower limit on run_eviction_loop loop frequency like at most once every 5 seconds. On the other hand I don't understand why the eviction loop is required at all if connection caching is disabled (idle_timeout = 0, ConnectionPool#cache_enabled? -> false).
As far as I can tell the code was heavily changed/rewritten with #328 by @mattbrictson. Maybe he can provide some guidance?
In any case, we can work with increasing the idle_timeout to >0 for now. I still like to have this problem fixed though.