This patch asks ActiveRecord to check and reestablish the connection
whenever the model is retrieved from Puppet::Indirector::ActiveRecord.
This fixes the reported error, but I suspect that we cannot completely
guarantee that we'll never reach a stale MySQL connection without
patching or upgrading ActiveRecord itself.
I don't have a unit test for this because it doesn't change any behavior
of Puppet. Suggestions on how to automate a test of this bug/fix would
be appreciated.
Signed-off-by: Jesse Wolfe <jes...@gmail.com>
---
lib/puppet/indirector/active_record.rb | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/puppet/indirector/active_record.rb b/lib/puppet/indirector/active_record.rb
index 531109a..c6031c8 100644
--- a/lib/puppet/indirector/active_record.rb
+++ b/lib/puppet/indirector/active_record.rb
@@ -10,7 +10,9 @@ class Puppet::Indirector::ActiveRecord < Puppet::Indirector::Terminus
end
def ar_model
- self.class.ar_model
+ ar_model = self.class.ar_model
+ ar_model.connection.verify!(30)
+ ar_model
end
def initialize
--
1.6.3.3
1) Minor, probably just my ignorance--what does the 30 do? Is it a time-value (e.g. 30 seconds or...?)
3) That brings up an interesting question (sorry I didn't think of this when we were talking yesterday); from the description on the ticket it sounds as if the problem might be unmoderated connection sharing between threads rather than timeouts. Did you look into that?
2) More serious: It's my understanding that the connection verify logic isn't thread safe and could mess things up if there are other threads using the connection.
> "allow_concurrency" may be worth following up on as well.
I'm nearly positive we took this out because we were getting warnings
from Rails saying it had been deprecated.
--
The people who are regarded as moral luminaries are those who forego
ordinary pleasures themselves and find compensation in interfering
with the pleasures of others. -- Bertrand Russell
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
> "allow_concurrency" may be worth following up on as well.I'm nearly positive we took this out because we were getting warnings
from Rails saying it had been deprecated.
> "allow_concurrency" may be worth following up on as well.I'm nearly positive we took this out because we were getting warnings
from Rails saying it had been deprecated.
It is indeed deprecated... as of ActiveRecord 2.2.x
This ticket was filed for AR 2.1.x, and I was under the impression Puppet supported that - I see now that the wiki ( http://reductivelabs.com/trac/puppet/wiki/UsingStoredConfiguration ) says it requires at least 2.2.2 . If that's true, then let's withdraw this patch and ask people to upgrade ActiveRecord.
Is the wiki really authoritative here? I thought that 2.1 was still
supported based on Luke's change in 1a5c5b3 (Fixing #2508 - removing
mention of ActiveRecord 2.3), which changed:
- raise "StoreConfigs not supported without ActiveRecord 2.3" unless Puppet.features.rails?
+ raise "StoreConfigs not supported without ActiveRecord 2.1 or higher" unless Puppet.features.rails?
If the wiki is accurate and 0.24.8 requires <= 2.2.2 and 0.25.x
requires >= 2.2.2, it seems like it will be difficult to support both
Fedora and RHEL/CentOS, as Fedora is at 2.3.4 and EPEL is at 2.1.1.
For distribution packagers, asking folks to install via gem is not an
option. And if EPEL can only support 0.24.8, updating Fedora to
0.25.1 gets fun, as many users likely have the puppetmaster on
RHEL/CentOS.
Please forgive me if I'm misunderstanding.
--
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The most overlooked advantage to owning a computer is that if they
foul up, there's no law against whacking them around a little.
-- Eric Porterfield
>> http://reductivelabs.com/trac/puppet/wiki/UsingStoredConfigurationIs the wiki really authoritative here? I thought that 2.1 was still
>> ) says it requires at least 2.2.2 . If that's true, then let's
>> withdraw this patch and ask people to upgrade ActiveRecord.
>
> Don't forget to add a note to that effect to the ticket and change
> it from "Investigating" to "Rejected."
supported based on Luke's change in 1a5c5b3 (Fixing #2508 - removing
mention of ActiveRecord 2.3), which changed:
- raise "StoreConfigs not supported without ActiveRecord 2.3" unless Puppet.features.rails?
+ raise "StoreConfigs not supported without ActiveRecord 2.1 or higher" unless Puppet.features.rails?
Please forgive me if I'm misunderstanding.
Right now, no (which is the bug in question that this whole thread is
trying to address).
Should it be supported, I'd say yes, since this is a regression from
0.24.8 and it's not in the release notes.
Of course the workaround is to upgrade rails to 2.2 or 2.3, it's just
that it generates support request, and/or request rails >= 2.2 in the
rails feature.
--
Brice Figureau
My Blog: http://www.masterzen.fr/
I thought we were compatible, but I guess having removed this line
(which got rid of a warning with newer versions of Rails) we've hurt
performance on older versions.
I'm comfortable adding it back in, but it should be done in a way
that's version-sensitive.
And ftr, the reason I added 2.1 support back in was 1) it seemed to
actually work for everyone and 2) it's quite difficult to use Puppet
to upgrade Rails without having multiple versions supported at once.
--
You wake me up early in the morning to tell me I am right? Please
wait until I am wrong. -- Johann von Neumann
> So perhaps we should address that head on. Is Rails 2.1 supported with
> 0.25.x?
Right now, no (which is the bug in question that this whole thread is
trying to address).
Should it be supported, I'd say yes, since this is a regression from
0.24.8 and it's not in the release notes.
I don't think that's likely to happen in EPEL, or even within a
released version of Fedora (though only the soon to be EOL Fedora 10
has rails < 2.2.2).
In just the past month or so, a security bug in ActiveSupport was
fixed by updating from 2.3.2 to 2.3.3 and this exposed a problem in
that rails apps hardcode the version by default (why they do this, I
don't think I want to know ;).
There was much discussion of this in the bug report, starting around:
https://bugzilla.redhat.com/show_bug.cgi?id=520843
In the end, the update was reverted to not break backwards
compatibility on released versions. I would suspect the same argument
holds for not updating the ActiveRecord package in Fedora and EPEL?
If so, I think it would mean that bumping the required version to
2.2.2 prevents us from pushing 0.25.1 to EPEL. :/ But maybe David or
others know differently -- I surely don't know the rails stack well.
But I can understand the pickle that trying to support older versions
puts everyone in. (I do wish that the rails folks wouldn't make
things so ...interesting.)
--
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Going to trial with a lawyer who considers your whole life-style a
Crime in Progress is not a happy prospect.
-- Hunter S. Thompson
But I can understand the pickle that trying to support older versions
puts everyone in. (I do wish that the rails folks wouldn't make
things so ...interesting.)
Signed-off-by: Jesse Wolfe <jes...@gmail.com>
---
lib/puppet/rails.rb | 4 ++++
spec/unit/rails.rb | 11 +++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index fc8eacd..87f1bb1 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -22,6 +22,10 @@ module Puppet::Rails
ActiveRecord::Base.logger.level = Logger::DEBUG
end
+ if (::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1)
+ ActiveRecord::Base.allow_concurrency = true
+ end
+
ActiveRecord::Base.verify_active_connections!
begin
diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb
index d98c887..6dee55b 100755
--- a/spec/unit/rails.rb
+++ b/spec/unit/rails.rb
@@ -39,6 +39,7 @@ describe Puppet::Rails, "when initializing any connection" do
ActiveRecord::Base.stubs(:logger).returns(logger)
logger.expects(:level=).with(Logger::DEBUG)
+ ActiveRecord::Base.stubs(:allow_concurrency=)
ActiveRecord::Base.stubs(:verify_active_connections!)
ActiveRecord::Base.stubs(:establish_connection)
Puppet::Rails.stubs(:database_arguments)
@@ -46,6 +47,16 @@ describe Puppet::Rails, "when initializing any connection" do
Puppet::Rails.connect
end
+ describe "on ActiveRecord 2.1.x" do
+ confine "ActiveRecord 2.1.x" => (::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1)
+
+ it "should set ActiveRecord::Base.allow_concurrency" do
+ ActiveRecord::Base.expects(:allow_concurrency=).with(true)
+
+ Puppet::Rails.connect
+ end
+ end
+
it "should call ActiveRecord::Base.verify_active_connections!" do
ActiveRecord::Base.expects(:verify_active_connections!)
--
1.6.3.3