Whenever we create a new MessagingPort, its address gets added to a global ports object. We may create MessagingPort objects in Listener::listen() or in DBClientConnection::connect(), and the db mutex need not be held in either context. It looks like the MessagingPort objects created by Listener are never destroyed, but the ones created by DBClientConnection get destroyed when the connection is destroyed. On destruction MessagingPort objects are removed from the 'ports' set, and this isn't done in a thread safe manner either.
Resulted in a seg fault here:
<http://buildbot.mongodb.org/builders/OS%20X%2010.5%2032-bit/builds/372/steps/test_3/logs/stdio>