Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1221

Ensure that 12 byte value of BSON::ObjectId clones matches original

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.2.2, bson-3.2.7
    • Affects Version/s: bson-4.2.1
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      centos 7, ruby 2.4.1, mongoid 6.1 bson 4.2.1

      Greetings,

      There is an apparent "overwrite" regarding the mongoid id, that appears to be a race condition. This is present, when creating a mongoid document and then immediately asking for it's id, twice.

        # create test document
        doc = TestDoc.new(stuff: 'hello world')
      
        # immediately grab "id"
        id_clone = doc.id.clone # must clone, otherwise ruby will point to the same object
        ids = doc.id.to_s
      
        if id_clone.to_s != ids
          puts "(id_clone) #{id_clone} != (doc.id.to_s) #{ids}"
          sleep 0.01
          puts "(doc.id) #{doc.id} != (doc.id.to_s) #{doc.id.to_s}" # matches up now
          exit
        end
      

      I attempted to trace down the race condition and ran into the native extension and got.. confused.

      This bug is present in Mongoid 5.1.6 as well.

      Thank you for your hard work!

      -daniel

        1. Gemfile
          0.1 kB
        2. Gemfile2
          0.1 kB
        3. try.rb
          0.6 kB
        4. try2.rb
          1 kB

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            wilburlo123 Daniel Lo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: