Cleaning up old submitted patches. This patch had some commentary on it from both Todd, and Markus that it was insufficient/incorrect when Rein submitted it originally. There is also some commentary on the ticket itself[1] that shows it doesn't appear to address the issue.
[1] http://projects.puppetlabs.com/issues/3238#note-29 -- Jacob Helwig On Tue, 24 May 2011 05:02:35 +1000, James Turnbull wrote: > > From: Rein Henrichs <[email protected]> > > ActiveRecord does not release connections back to its connection pool > automatically. This patch forces ActiveRecord to release its own > connections. > > Signed-off-by: James Turnbull <[email protected]> > --- > Local-branch: tickets/2.7.x/3238 > lib/puppet/rails.rb | 2 + > lib/puppet/rails/activerecord_connections.rb | 50 > ++++++++++++++++++++++++++ > 2 files changed, 52 insertions(+), 0 deletions(-) > create mode 100644 lib/puppet/rails/activerecord_connections.rb > > diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb > index f74e63f..939394a 100644 > --- a/lib/puppet/rails.rb > +++ b/lib/puppet/rails.rb > @@ -74,6 +74,8 @@ module Puppet::Rails > def self.init > raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails" > unless Puppet.features.rails? > > + require 'lib/puppet/rails/activerecord_connections' # Patch for #3238 > + > connect > > unless ActiveRecord::Base.connection.tables.include?("resources") > diff --git a/lib/puppet/rails/activerecord_connections.rb > b/lib/puppet/rails/activerecord_connections.rb > new file mode 100644 > index 0000000..6281180 > --- /dev/null > +++ b/lib/puppet/rails/activerecord_connections.rb > @@ -0,0 +1,50 @@ > +module ActiveRecord > + module ConnectionAdapters > + class ConnectionPool > + def cleanup_connection > + return yield if Thread.current[:__AR__cleanup_connection] > + > + begin > + Thread.current[:__AR__cleanup_connection] = true > + yield > + ensure > + release_connection > + Thread.current[:__AR__cleanup_connection] = false > + end > + end > + end > + end > +end > + > +methods_to_wrap = { > + (class<<ActiveRecord::Base;self;end) => [ > + :find, :find_every, :find_by_sql, :transaction, :count, :create, > :delete, :count_by_sql, > + :update, :destroy, :cache, :uncached, :quoted_table_name, :columns, > :exists?, :update_all, > + :increment_counter, :decrement_counter, :delete_all, :table_exists?, > :update_counters, > + ], > + ActiveRecord::Base => [:quoted_id, :valid?], > + ActiveRecord::Associations::AssociationCollection => [:initialize, :find, > :find_target, :load_target, :count], > + ActiveRecord::Associations::HasAndBelongsToManyAssociation => [:create], > + ActiveRecord::Associations::HasManyThroughAssociation => > [:construct_conditions], > + ActiveRecord::Associations::HasOneAssociation => [:construct_sql], > + ActiveRecord::Associations::ClassMethods => [:collection_reader_method, > :configure_dependency_for_has_many], > + ActiveRecord::Calculations::ClassMethods => [:calculate], > +} > +methods_to_wrap[Test::Unit::TestSuite] = [:run] if > defined?(Test::Unit::TestSuite) > + > +methods_to_wrap.each do |klass, methods| > + methods.each do |method| > + klass.class_eval do > + alias_method_chain method, :cleanup_connection do |target, punc| > + eval %{ > + def #{target}_with_cleanup_connection#{punc}(*a, &b) > + ActiveRecord::Base.connection_pool.cleanup_connection do > + #{target}_without_cleanup_connection#{punc}(*a, &b) > + end > + end > + } > + end > + end > + end > +end > + > -- > 1.7.1 > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. >
signature.asc
Description: Digital signature
