Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28103

ReplicationCoordinatorImpl::canAcceptWritesForDatabase() reads _canAcceptNonLocalWrites without proper locking

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Replication
    • None
    • Fully Compatible
    • ALL
    • 0

      _mutex should be locked before reading _canAcceptNonLocalWrites.

      https://github.com/mongodb/mongo/blob/14f16f384a2ace3b5ccb45dcbfbb66f3f57e945a/src/mongo/db/repl/replication_coordinator_impl.cpp#L1875

      bool ReplicationCoordinatorImpl::canAcceptWritesForDatabase(StringData dbName) {
          // _canAcceptNonLocalWrites is always true for standalone nodes, always false for nodes
          // started with --slave, and adjusted based on primary+drain state in replica sets.
          //
          // That is, stand-alone nodes, non-slave nodes and drained replica set primaries can always
          // accept writes.  Similarly, writes are always permitted to the "local" database.  Finally,
          // in the event that a node is started with --slave and --master, we allow writes unless the
          // master/slave system has set the replAllDead flag.
          if (_canAcceptNonLocalWrites) {
              return true;
          }
          if (dbName == kLocalDB) {
              return true;
          }
          return !replAllDead && _settings.isMaster();
      }
      

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            benety.goh@mongodb.com Benety Goh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: