From 045c77c1bc8f9acdc7efe34ba7af59acfe6f955f Mon Sep 17 00:00:00 2001 From: Will Bryant Date: Wed, 3 Sep 2014 00:12:52 +1200 Subject: [PATCH] Fix Issue #15549, unbounded memory growth when saving records that have any after_create callbacks (or any associations, which makes after_create callbacks for you) --- activerecord/lib/active_record/core.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 6ed5dd0bfa..c1eaa4f49b 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -489,7 +489,7 @@ module ActiveRecord end def has_transactional_callbacks? # :nodoc: - !_rollback_callbacks.empty? || !_commit_callbacks.empty? || !_create_callbacks.empty? + !_rollback_callbacks.empty? || !_commit_callbacks.empty? end # Updates the attributes on this particular ActiveRecord object so that @@ -514,6 +514,8 @@ module ActiveRecord end def update_attributes_from_transaction_state(transaction_state, depth) + @reflects_state = [false] if depth == 0 + if transaction_state && transaction_state.finalized? && !has_transactional_callbacks? unless @reflects_state[depth] restore_transaction_record_state if transaction_state.rolledback? @@ -550,7 +552,6 @@ module ActiveRecord @txn = nil @_start_transaction_state = {} @transaction_state = nil - @reflects_state = [false] end def initialize_internals_callback