Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2985

Thread safety across sessions/storage

      I hope this message finds you well.

      We're having some issues with Mongoid on JRuby+Puma where the collection associated with a Mongoid model is being changed incorrectly.

      The issue presents itself after a few requests. You'll see the hash of attributes from one collection being materialised within the wrong model, so based on the code example below, a Person will show up with a species attribute instead of a name, and vice-versa.

      The issue appeared to be exacerbated by the use of includes although this may have been a coincidence.

      Some example code to reproduce follows.

       ruby
      class Person
        has_many :pets
      
        field :name
      end
      
      class Pet
        belongs_to :person
      
        field :species
      end
      
      50.times do
        Thread.new do
          Person.store_in collection: 'people'
          Pet.store_in collection: 'pets'
        end
      end
      
      Person.collection.name # => 'pets'
      Pet.collection.name # => 'pets'
      

      Any pointers, or help would be most appreciated. I can provide more information on our exact setup if that helps.

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            jcf jcf
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: