cbrain icon indicating copy to clipboard operation
cbrain copied to clipboard

Race condition when creating new meta data keys

Open prioux opened this issue 9 years ago • 0 comments

There's a tiny race condition when two processes try to create the same meta data key on the same object. The save! method raises an exception because the object trying to be created already exists.

The code is this method:

    def set_attribute(mykey,myval) #:nodoc:
      return delete_attribute(mykey) if myval.nil?
      mykey = mykey.to_s
      md = self.md_cache[mykey] || MetaDataStore.new( :ar_id => self.ar_id, :ar_table_name => self.ar_table_name, :meta_key => mykey )
      md_cache[mykey] = md
      if md.meta_value != myval
        md.meta_value   = myval
        md.save!
      end
      myval
    end

The solution might involved a ruby redo, or trying to reload the object, or ignoring altogether the exception!

prioux avatar Dec 06 '16 16:12 prioux