We are using smart pointers to initialize mongo connection pool. Following is code snippet:
mongoc_init(); mongoc_log_set_handler(mongoLogHandler, nullptr); mongoc_uri_t* p_uri = mongoc_uri_new(mongo_complete.c_str()); assert(p_uri); // shared ptr with custom deleter auto sp_pool = shared_ptr<mongoc_client_pool_t>( mongoc_client_pool_new(p_uri), [](mongoc_client_pool_t * p) { * mongoc_client_pool_destroy(p);* mongoc_cleanup(); } ); assert(sp_pool); mongoc_uri_destroy(p_uri);
But application seems to hang when mongoc_client_pool_destroy(p) is called. Further debugging shows it is waiting at the following code (mongoc-topology.c):
topology->bg_thread_state = MONGOC_TOPOLOGY_BG_SHUTTING_DOWN;
_ topology->shutdown_requested = true; mongoc_cond_signal (&topology->cond_server); *topology->bg_thread_state = MONGOC_TOPOLOGY_BG_SHUTTING_DOWN;* join_thread = true;_
Although if we remove the mongoc_client_pool_destroy(p) then application seems to work fine.
Any ideas what would be the reason behind the hang?