提交 2c667f69 编写于 作者: J Jon Leighton

Fix race condition 💣

上级 8a3dcd71
require 'active_support/core_ext/enumerable' require 'active_support/core_ext/enumerable'
require 'active_support/deprecation' require 'active_support/deprecation'
require 'thread'
module ActiveRecord module ActiveRecord
# = Active Record Attribute Methods # = Active Record Attribute Methods
...@@ -35,10 +36,16 @@ module ClassMethods ...@@ -35,10 +36,16 @@ module ClassMethods
# Generates all the attribute related methods for columns in the database # Generates all the attribute related methods for columns in the database
# accessors, mutators and query methods. # accessors, mutators and query methods.
def define_attribute_methods def define_attribute_methods
return if attribute_methods_generated? # Use a mutex; we don't want two thread simaltaneously trying to define
superclass.define_attribute_methods unless self == base_class # attribute methods.
super(column_names) @attribute_methods_mutex ||= Mutex.new
@attribute_methods_generated = true
@attribute_methods_mutex.synchronize do
return if attribute_methods_generated?
superclass.define_attribute_methods unless self == base_class
super(column_names)
@attribute_methods_generated = true
end
end end
def attribute_methods_generated? def attribute_methods_generated?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册