Uh oh!
There was an error while loading. Please reload this page.
Fix Disabling of Connection Pool - #448
Conversation
Generated by 🚫 Danger |
leehambley
commented
Jan 29, 2019
@tisba thanks for the submission, this seems like a great fix. It's dirt simple, and the explanation in the PR is longer than the code sample, which inspires confidence. I've requested a review from @mattbrictson if he's OK with it, let's roll it and get it out in the next release! |
tisba
commented
Jan 29, 2019
Nice! Do you want to me to update the changelog, as the nice @capistrano-bot mentioned? :) Also, what about the other suggestion regarding the slight adjustment of the eviction loop as well? |
leehambley
commented
Jan 29, 2019
Probably a good idea!
That concerns me somewhat more than this, lets keep them separate? @mattbrictson what do you think? |
Uh oh!
There was an error while loading. Please reload this page.
mattbrictson
commented
Jan 29, 2019
I think it is safe to include. Just to clarify, we're talking about changing this line: sleep([idle_timeout,5].min)to be: sleep(5)correct?
I am OK with accepting the PR without tests. Thanks so much for this PR! 🙏 |
Co-Authored-By: tisba <tisba@users.noreply.github.com>
tisba
commented
Jan 30, 2019
This is exactly the change I would like to suggest. With 162cbfd the eviction of timed out connection could obviously take a couple of seconds, but (like I already outlined) the semantics of "will eventually be closed/removed" is not something that users of sshkit should be surprised by. |
leehambley
commented
Jan 30, 2019
Danke für den Einsatz! Thanks for your contribution, may your SideKiq workers spin less frequently on a busy loop! 🏆 |
mattbrictson
commented
Jan 30, 2019
We generally publish new SSHKit releases to rubygems every six weeks, and since the most recent release was just a few days ago, that would mean this fix doesn't get published until about 5 weeks from now. But I'm happy to make exceptions for important bug fixes. Does this qualify? |
tisba
commented
Jan 31, 2019
IMO this is a nasty bug, even though sshkit users might run into it only extreme rare cases. What makes it "worse" IMO, is that the current README (regarding the ability to disable the connection cache) directly leads to the issue fixed by this PR. On the other hand the mitigation (once you've figured out what is going on), is rather trivial: Don't disable the connection pool. Me personally I'm okay with not rushing this. |
mattbrictson
commented
Feb 3, 2019
Actually, I'll make a release today. These sorts of major bug fixes don't happen very often. |
mattbrictson
commented
Feb 3, 2019
🚀 released as 1.18.2 |
Update ruby-sshkit package to 1.20.0. ## [1.20.0][] (2019-08-03) * [#468](capistrano/sshkit#468): Make `upload!` take a `:verbosity` option like `exec` does - [@grosser](https://github.com/grosser) ## [1.19.1][] (2019-07-02) * [#465](capistrano/sshkit#456): Fix a regression in 1.19.0 that prevented `~` from being used in Capistrano paths, e.g. `:deploy_to`, etc. - [@grosser](https://github.com/grosser) ## [1.19.0][] (2019-06-30) * [#455](capistrano/sshkit#455): Ensure UUID of commands are stable in logging - [@lazyatom](https://github.com/lazyatom) * [#453](capistrano/sshkit#453): `as` and `within` now properly escape their user/group/path arguments, and the command nested within an `as` block is now properly escaped before passing to `sh -c`. In the unlikely case that you were manually escaping commands passed to SSHKit as a workaround, you will no longer need to do this. See [#458](capistrano/sshkit#458) for examples of what has been fixed. - [@grosser](https://github.com/grosser) * [#460](capistrano/sshkit#460): Handle IPv6 addresses without port - [@will-in-wi](https://github.com/will-in-wi) ## [1.18.2][] (2019-02-03) * [#448](capistrano/sshkit#448): Fix misbehaving connection eviction loop when disabling connection pooling - [Sebastian Cohnen](https://github.com/tisba) ## [1.18.1][] (2019-01-26) * [#447](capistrano/sshkit#447): Fix broken thread safety by widening critical section - [Takumasa Ochi](https://github.com/aeroastro)
Update ruby-sshkit package to 1.20.0. ## [1.20.0][] (2019-08-03) * [#468](capistrano/sshkit#468): Make `upload!` take a `:verbosity` option like `exec` does - [@grosser](https://github.com/grosser) ## [1.19.1][] (2019-07-02) * [#465](capistrano/sshkit#456): Fix a regression in 1.19.0 that prevented `~` from being used in Capistrano paths, e.g. `:deploy_to`, etc. - [@grosser](https://github.com/grosser) ## [1.19.0][] (2019-06-30) * [#455](capistrano/sshkit#455): Ensure UUID of commands are stable in logging - [@lazyatom](https://github.com/lazyatom) * [#453](capistrano/sshkit#453): `as` and `within` now properly escape their user/group/path arguments, and the command nested within an `as` block is now properly escaped before passing to `sh -c`. In the unlikely case that you were manually escaping commands passed to SSHKit as a workaround, you will no longer need to do this. See [#458](capistrano/sshkit#458) for examples of what has been fixed. - [@grosser](https://github.com/grosser) * [#460](capistrano/sshkit#460): Handle IPv6 addresses without port - [@will-in-wi](https://github.com/will-in-wi) ## [1.18.2][] (2019-02-03) * [#448](capistrano/sshkit#448): Fix misbehaving connection eviction loop when disabling connection pooling - [Sebastian Cohnen](https://github.com/tisba) ## [1.18.1][] (2019-01-26) * [#447](capistrano/sshkit#447): Fix broken thread safety by widening critical section - [Takumasa Ochi](https://github.com/aeroastro)
Update ruby-sshkit package to 1.20.0. ## [1.20.0][] (2019-08-03) * [#468](capistrano/sshkit#468): Make `upload!` take a `:verbosity` option like `exec` does - [@grosser](https://github.com/grosser) ## [1.19.1][] (2019-07-02) * [#465](capistrano/sshkit#456): Fix a regression in 1.19.0 that prevented `~` from being used in Capistrano paths, e.g. `:deploy_to`, etc. - [@grosser](https://github.com/grosser) ## [1.19.0][] (2019-06-30) * [#455](capistrano/sshkit#455): Ensure UUID of commands are stable in logging - [@lazyatom](https://github.com/lazyatom) * [#453](capistrano/sshkit#453): `as` and `within` now properly escape their user/group/path arguments, and the command nested within an `as` block is now properly escaped before passing to `sh -c`. In the unlikely case that you were manually escaping commands passed to SSHKit as a workaround, you will no longer need to do this. See [#458](capistrano/sshkit#458) for examples of what has been fixed. - [@grosser](https://github.com/grosser) * [#460](capistrano/sshkit#460): Handle IPv6 addresses without port - [@will-in-wi](https://github.com/will-in-wi) ## [1.18.2][] (2019-02-03) * [#448](capistrano/sshkit#448): Fix misbehaving connection eviction loop when disabling connection pooling - [Sebastian Cohnen](https://github.com/tisba) ## [1.18.1][] (2019-01-26) * [#447](capistrano/sshkit#447): Fix broken thread safety by widening critical section - [Takumasa Ochi](https://github.com/aeroastro)
Fixes#438
The README currently states, that:
will disable the cache and this can be used to mitigate potential problems from connection pooling. As described in #438 quite the opposite was the case. Connections were not cached, BUT the cache eviction loop was still started. With
idle_timeout = 0the the eviction loop becomes a busy loop hogging one core at 100%.This PR will skip the launch of the eviction loop (via
run_eviction_loop) in case the cache is disabled. If the cache is disabled, there can't be anytimed_out_connectionsbecausesilently_close_connection_lateris not used.find_cachedoes not usethread_safe_find_or_create_cacheif cache is disabled:sshkit/lib/sshkit/backends/connection_pool.rb
Lines 98 to 106 in ac18160
I'd like to get some guidance on how to test this (@leehambley maybe?).
Further Suggestion
I also would like to propose that there is a maximum eviction frequency. The
idle_timeoutshould not guarantee when idle connections are removed. Rather it should be considered "afteridle_timeoutsshkit will evict the connection eventually; never before". If you agree with this, we could simplify thesleepfrom this:sshkit/lib/sshkit/backends/connection_pool.rb
Lines 129 to 139 in ac18160
to