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

Race condition in authentication code

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.21.1
    • Affects Version/s: 2.20.1
    • Component/s: None
    • None
    • None
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      This describes an error from a race-condition that will occasionally happen when there is continuous multithreaded authentication occurring. 

      While the Mongo::Auth::CredentialCache is being written to, the value will go through a phase, such that if it is retrieved a particular moment, it will return false (value is never actually set to false by the code, somehow the underlying Ruby code behaves this way). The cache code does check if the value is nil, but will consider the value false to be a cache hit. As a result, The methods client_key and server_key in scram_conversion_base.rb may incorrectly return false instead of the value from the block. This will result in an error "no implicit conversion of false into String" when attempting to use the "false" value for authentication.

      In our testing, we found that protecting the cache with a mutex resolves this problem.

      Of note is that the two other caches in this library are already made theadsafe. These are Mongo::Auth::Aws::CredentialsCache (auth/aws/credentials_cache.rb) [not to be confused with Mongo::Auth::CredentialCache] which is protected with a Mutex and Mongo::QueryCache (query_cache.rb) which is protected with a ThreadLocal variable.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            joseph.teichman@braze.com Joseph Teichman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: