[CXX-2620] mongocxx 3.7.2 crashes when I build my project in release mode Created: 07/Dec/22  Updated: 27/Oct/23  Resolved: 28/Dec/22

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Vlad Vlad Assignee: Kyle Kloberdanz
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

I am building mongocxx, mongo-c-driver in release mode and my project was built in debug mode, this configuration worked but when I build my project in release mode I get an error:

 

Thread 1 (LWP 11721):
#0  0x000000000061444f in __wrap_free ()
#1  0x00007fefdded4562 in mongocxx::v_noabi::database::_run_command(mongocxx::v_noabi::client_session const*, bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>) () from /nix/store/n11rgm9m6jmkvk1bf0lklzph6qgjwx9x-mongocxx/lib/libmongocxx.so._noabi
#2  0x00007fefdded4739 in mongocxx::v_noabi::database::run_command(bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>) () from /nix/store/n11rgm9m6jmkvk1bf0lklzph6qgjwx9x-mongocxx/lib/libmongocxx.so._noabi
 

The code:

 

bool MongoDBClient::connected(mongocxx::database& db) const {  
  using namespace std::chrono_literals;    
  logInfo("Try to ping mongo");    
  std::this_thread::sleep_for(1s);    
  try {        
     auto result = db.run_command(make_document(kvp("ping", 1))); 
     if (result.view()["ok"].get_double().value != 1) {
            return false;
     }
    } catch (const std::exception& e) {
        logWarn("Mongo ping does not work {}", e.what());
        return false;
    }
    logInfo("Mongo is ok");
    return true;
} 
 
 
auto pool = std::make_shared<mongocxx::pool>(mongocxx::uri{configuration});
auto connection_ptr = pool->acquire();
auto db             = connection_ptr->database(name);                       auto ok = connected(db);

I use nixos and when building I tried to use versions 1.21.1, 1.22.0 and 3.7.2 for mongo-c-driver and mongocxx respectively:

// mongo-c-client
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$out \ -DBUILD_VERSION=${version} -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
// mongocxx
cmake .. -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$out \ -DBUILD_VERSION=${version} -DCMAKE_CXX_STANDARD=20

Environment

OS: nix-os

Compiler: GCC x86_64-unknown-linux-gnu/11.3.0

Mongo-c-driver: 1.21.0, 1.22.1
Mongocxx: 3.6.6, 3.7.2

 



 Comments   
Comment by PM Bot [ 28/Dec/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Kyle Kloberdanz [ 13/Dec/22 ]

Thank you for reporting this issue. We need a little more information to help us in our investigation.

  1. What was allocated that triggered this issue (i.e., which object type, from which method/function, etc)?
  2. What is the solution that you found to fix the problem that you encountered?
  3. I am unable to reproduce the issue with the provided code snippet in the ticket. Do you have a minimum code snippet to reproduce this issue?

Thanks again for reporting the issue.

Comment by Vlad Vlad [ 08/Dec/22 ]

We found a solution, but developers should take a look anyway: there was different malloc/free in different compilation units.
That is, something was allocated by the malloc () that is in our project, and inside libmongocxx its own free () was used

Generated at Wed Feb 07 22:06:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.