Skip to content

ConnectionPool: idle_timeout of 0 causes 100% and busy looping #438

@tisba

Description

@tisba

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 = 0

Which causes a busy loop in ConnectionPool#run_eviction_loop as [idle_timeout, 5].min will be 0:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions