mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix race condition 💣
This commit is contained in:
parent
8a3dcd716c
commit
2c667f69aa
1 changed files with 11 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'active_support/core_ext/enumerable'
|
||||
require 'active_support/deprecation'
|
||||
require 'thread'
|
||||
|
||||
module ActiveRecord
|
||||
# = Active Record Attribute Methods
|
||||
|
@ -35,11 +36,17 @@ module ActiveRecord
|
|||
# Generates all the attribute related methods for columns in the database
|
||||
# accessors, mutators and query methods.
|
||||
def define_attribute_methods
|
||||
# Use a mutex; we don't want two thread simaltaneously trying to define
|
||||
# attribute methods.
|
||||
@attribute_methods_mutex ||= Mutex.new
|
||||
|
||||
@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
|
||||
|
||||
def attribute_methods_generated?
|
||||
@attribute_methods_generated ||= false
|
||||
|
|
Loading…
Reference in a new issue