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

Query consistency issues under load

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      We were testing mongoid-locker, because we detected consistency issues (two threads entered lock at the same time). After simplifying the test scenario and removing mongoid-locker and mongoid dependencies we concluded that in following case two threads are able to update the same document:

      db[:wallets].update_one({
        :_id => id,
        '$or' => [
          # not locked
          { locked_until: nil },
          # expired
          { locked_until: { '$lte' => time } }
         ]
        },
      
        '$set' => {
           locked_at: time,
           locked_until: expiration
         }
      )
      

      I haven't found the exact reason for that. I prepared a test case in this repo:

      https://github.com/mrzasa/mongoid-locker-debugging/ 

      THREAD_COUNT=500 PROCESS_COUNT=2 bundle exec ruby test/raw_test.rb
      

      The issue happens when several threads tries to run updates to acquire the lock (as quoted above) and other unrelated updates on the same document.

      I am not sure if it's a bug in the ruby driver or mongo itself. As I reproduced it only in Ruby, I report it here. Further investigation is required to determine if it may happen in other drivers as well.

      I have tested it on mongo: 3.2.16, 3.2.17 and 4.0.5 on docker and ubuntu 18.04, Linux  4.15.0-33-generic #36-Ubuntu x86_64. I'm eager to share any further details of my test and provide assistance in fixing it.

       

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            mrzasa Maciej Rząsa
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: