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

Static destructor ordering problem between DBConnectionPool and Ports

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.4
    • Affects Version/s: 1.5.3
    • Component/s: Internal Client
    • None
    • Environment:
      ALL
    • ALL

      mongo::DBConnectionPool has a static instance, as does the mongo::Ports class. The destructor of a mongo::DBClientConnection requires the existence of the Port static object, and the DBConnectionPool static object destroys DBClientConnections. However, the static instance of the Ports class and the static instance of the DBConnectionPool are defined in separate translation units, and therefore there is no guaranteed ordering among the static destructors. This shows up in valgrind like this:

      ==26777== Invalid read of size 4
      ==26777== at 0x6D5A3C4: pthread_mutex_lock (pthread_mutex_lock.c:50)
      ==26777== by 0x984CA82: boost::unique_lock<boost::mutex>::unique_lock(boost::mutex&) (mutex.hpp:50)
      ==26777== by 0x9EF3394: mongo::mutex::scoped_lock::scoped_lock(mongo::mutex&) (mutex.h:154)
      ==26777== by 0x9F5E03F: mongo::Ports::erase(mongo::MessagingPort*) (message.cpp:262)
      ==26777== by 0x9F5AFC8: mongo::MessagingPort::~MessagingPort() (message.cpp:297)
      ==26777== by 0x9F72DB1: void boost::checked_delete<mongo::MessagingPort>(mongo::MessagingPort*) (checked_delete.hpp:34)
      ==26777== by 0x9F72500: boost::scoped_ptr<mongo::MessagingPort>::~scoped_ptr() (scoped_ptr.hpp:80)
      ==26777== by 0x9F824EE: mongo::DBClientConnection::~DBClientConnection() (dbclient.h:650)
      ==26777== by 0x9F70CC1: mongo::DBConnectionPool::~DBConnectionPool() (connpool.cpp:83)
      ==26777== by 0x90BB62F: __cxa_finalize (cxa_finalize.c:56)
      ==26777== by 0x9EE3645: ??? (in ~/mongo.temp.install/lib64/libmongoclient.so)
      ==26777== by 0x9F9F350: ??? (in ~/mongo.temp.install/lib64/libmongoclient.so)
      ==26777== by 0x90BB261: exit (exit.c:78)
      ==26777== by 0x90A0C53: (below main) (libc-start.c:258)
      ==26777== Address 0xdaa6a90 is 16 bytes inside a block of size 40 free'd
      ==26777== at 0x4C288AE: operator delete(void*) (vg_replace_malloc.c:405)
      ==26777== by 0x9F31B2D: mongo::mutex::~mutex() (mutex.h:146)
      ==26777== by 0x9F614B9: mongo::Ports::~Ports() (message.cpp:245)
      ==26777== by 0x90BB62F: __cxa_finalize (cxa_finalize.c:56)
      ==26777== by 0x9EE3645: ??? (in ~/mongo.temp.install/lib64/libmongoclient.so)
      ==26777== by 0x9F9F350: ??? (in ~/mongo.temp.install/lib64/libmongoclient.so)
      ==26777== by 0x90BB261: exit (exit.c:78)
      ==26777== by 0x90A0C53: (below main) (libc-start.c:258)

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: