[CXX-562] Intial object name mongo::client::initialize(); represent Program received signal SIGSEGV, Segmentation fault Created: 18/Mar/15 Updated: 01/Apr/15 Resolved: 01/Apr/15 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API, BSON |
| Affects Version/s: | legacy-1.0.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | rchatsiri | Assignee: | Adam Midvidy |
| Resolution: | Done | Votes: | 0 |
| Labels: | legacy-cxx | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Object mongo::client::intiailze() cannot initial mongo-client call to server when use legacy driver. After use gtest run mongo_connector binary file show as below. (gdb) bt Legacy source is version: commit 624146feb3bb74fe139b167af02d666e83f24e7d Command compiles legacy branch of C++ driver: scons --sharedclient --extrapath=/home/chatsiri/sda1/workspacecpp/boost_1_57_0 --cpppath=/home/chatsiri/sda1/workspacecpp/boost_1_57_0 --libpath=/home/chatsiri/sda1/workspacecpp/boost_1_57_0/stage/lib --cxx=/usr/bin/g++-4.8 --cc=/usr/bin/gcc-4.8 --dbg=on --prefix=/home/chatsiri/sda1/workspacecpp/mongo-cxx-driver/build install An example source code before was compiled to binary file. class mongo_conector{ ... |
| Comments |
| Comment by rchatsiri [ 01/Apr/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi @Adam Midvidy, Thank you for advise. In my programs, Other class call mongo_connector() constructor. It's still alive in memory for my case. I understand you point programs load only one constructor class. Would you close ticket-problem? Thank in advances, | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Midvidy [ 31/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi rchatsiri, the issue is that you are stack allocating a mongo::client::GlobalInstance in the mongo_connector() constructor. You should instead create a GlobalInstance in the main() block of your program. A GlobalInstance object should only be created once, and should stay in scope for the duration of your program. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by rchatsiri [ 26/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Adam Midvidy, Project complied by G+-4.8 which flag of standard library switch to -std=c+11. I found solving problem by initial connection object when implement global instance as below. It didn't show error after run test suite.
That full description in my code write in github respository. Global Instance and connection object implement both in mongo_connector class.
Thank in advance, | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Midvidy [ 25/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi rchatsiri, What version of C++ are you compiling the driver with, and what version are you compiling your application with? From the stack trace you gave it seems like the issue is a mismatched C++ version - either compiling the driver in C++11 mode and your application in C++03/98 mode or visa versa. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by rchatsiri [ 18/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello Adam Midvidy, In my project use google test of C++. Instance name mongo::client::GlobalInstance instance; cannot initial object when it's declares main object in the TEST(...) such
It's present an error as
My view, It's example class to call to instance object. Object name GlobalInstance should to call pass TDD class. Why cannot initials object in main class that is gtest? | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Midvidy [ 18/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hey Rchatsiri, It looks like you are calling mongo::client::initialize() in the constructor of your mongo_connector class. initialize() should only be called once in your program, and it must be called before any other driver functionality is used. Can you try taking the mongo::client::initialize() out of the mongo_connector constructor and putting it in the main() function of your program before any other driver functions are called? There is also a convenience wrapper, mongo::client::GlobalInstance that will manage the lifecycle of the driver for you. Your code would look like this:
| |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by rchatsiri [ 18/Mar/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Example on github wiki can run completed. #include <cstdlib> void run() { mongo::DBClientConnection c; c.connect("localhost"); }int main() { catch( const mongo::DBException &e ) { std::cout << "caught " << e.what() << std::endl; } return EXIT_SUCCESS; Command line to compile as below. g++-4.8 tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_system -lboost_regex -o tutorial -I/home/chatsiri/sda1/workspacecpp/mongo-cxx-driver/build/include -L/home/chatsiri/sda1/workspacecpp/mongo-cxx-driver/build/ |