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

Memory leaks from DatabaseHolder::getOrCreate() and related

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.3, 2.4.0-rc2
    • Component/s: MMAPv1, Storage
    • None
    • Storage Execution
    • ALL
    • Hide
      for (var i = 0; i<100000; i++) {
        var x = db.getSiblingDB('foo'+i).foo.findOne();
      }
      
      Show
      for (var i = 0; i<100000; i++) { var x = db.getSiblingDB('foo'+i).foo.findOne(); }
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      There appear to be several related leaks present:

      • DatabaseHolder::getOrCreate() allocates a new Database object and stores this pointer in _paths[path][dbname]. Although Database::closeDatabase() removes these entries, there doesn't seem to be any logic to remove entries for a database that is created but not written to.
      • When we getOrCreate() a db that's never used, the global mmfiles set is updated with a MongoFile* that has no file name. There is a comment in MongoFile::destroyed() which indicates this function should be called when a derived class is destroyed. However, ~MongoMMF() doesn't appear to be called for a database which is not written to. Note that ~MongoMMF() calls MongoMMF::close(), which calls MemoryMappedFile::close(), which finally calls MongoFile::destroy(). ~MongoMMF() is called from a few places; notably ~MongoDataFile(), ~NamespaceIndex(), and the journal recovery code.
      • There are additional leaks that have not yet been identified, but can be reproduced with the repro script. The script not only causes a leak when the unused databases are 'accessed', but also a continuously increasing leak while mongod remains alive. The leak rate is about 2mb per minute when the attached script is reduced to only execute 100 iterations.

      *Also, possibly worth noting, DataFileSync must iterate over all unique unwritten database names.

            Assignee:
            backlog-server-execution [DO NOT USE] Backlog - Storage Execution Team
            Reporter:
            benjamin.becker Ben Becker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: