[SERVER-1276] Static destructor ordering problem between DBConnectionPool and Ports Created: 21/Jun/10  Updated: 12/Jul/16  Resolved: 01/Jul/10

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 1.5.3
Fix Version/s: 1.5.4

Type: Bug Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ALL


Operating System: ALL
Participants:

 Description   

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)



 Comments   
Comment by auto [ 01/Jul/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: Static destruction order fix SERVER-1276
http://github.com/mongodb/mongo/commit/ae2aa8a24552ab035ead84eb49fcc17270beb522

Comment by Roman Shtylman [ 01/Jul/10 ]

In 1.5.3 this issue has become more serious and appears to cause an assertion failure when libmongoclient is built as a shared object. The crash happens on shutdown.

backtrace:
#0 0x00007ffff3389a75 in *__GI_raise (sig=<value optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff338d5c0 in *__GI_abort () at abort.c:92
#2 0x00007ffff3382941 in *_GI__assert_fail (assertion=0x7ffff27cd895 "!pthread_mutex_lock(&m)", file=<value optimized out>, line=50, function=0x7ffff27e1c20 "void boost::mutex::lock()") at assert.c:81
#3 0x00007ffff2783b87 in mongo::MessagingPort::~MessagingPort() () from /usr/lib/libmongoclient.so.1.5.3
#4 0x00007ffff27ad905 in mongo::DBClientConnection::~DBClientConnection() () from /usr/lib/libmongoclient.so.1.5.3
#5 0x00007ffff2799bef in mongo::DBConnectionPool::~DBConnectionPool() () from /usr/lib/libmongoclient.so.1.5.3
#6 0x00007ffff338f630 in __cxa_finalize (d=0x7ffff2a09850) at cxa_finalize.c:56
#7 0x00007ffff2732856 in ?? () from /usr/lib/libmongoclient.so.1.5.3
#8 0x0000000000000030 in ?? ()
#9 0x0000000000000000 in ?? ()

Generated at Thu Feb 08 02:56:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.