Re: MongoDB C++ Driver - GlobalInitializerRegisterer ends up with a status: DuplicateKey throwSockExcep

279 views
Skip to first unread message

Tyler Brock

unread,
May 22, 2013, 11:50:48 AM5/22/13
to mongod...@googlegroups.com
What is the operation that throws this error in Accessop?

There is a unique index on _id so if a document is being inserted in safe mode and it exists this will cause an exception to be thrown.

-Tyler

On Tuesday, May 21, 2013 2:42:36 PM UTC-4, Paweł Skorupiński wrote:
I am trying to run mongoDB client under C++ as a part of my shared library on 64-bit Ubuntu.

I have downloaded nightly version of mongodb c++ driver, as explained step-by-step at http://programmingknowledgeblog.blogspot.de/2013/02/how-to-run-and-install-mongo-c-drivers.html. I have (only?) changed the SConfigure script by adding -fPIC flag to CCFLAGS, because (as far as I know) there is no other way to link static library with shared library under 64-bit system. Then I have installed mongodb driver using scons.

I have run MongoDB server as well, using
mongodb-10gen version.

I have defined linking to shared libraries in CMakeLists.txt file. It looks like this:

target_link_libraries(MyGridFS mongoclient boost_thread-mt boost_filesystem-mt boost_program_options-mt)
target_link_libraries(MongoDbDataSourceAdapter MyGridFS)
target_link_libraries(Accessop SMOperatorInitParam SMByteArrayHeader MongoDbDataSourceAdapter RealTimeDataSourceAdapter EndOfStreamHandler)


 Now, it is enough that Accessop.so is called (not even a line of code is executed - furthermore, the code I use right now in Accessop class does not use mongoDB functionality at all) and such an exception appears:

Attempt to add global initializer failed, status: DuplicateKey throwSockExcep
Caught signal (6)
Stacktrace:
    at gsignal (/lib/x86_64-linux-gnu/libc.so.6)
    at abort (/lib/x86_64-linux-gnu/libc.so.6)
    at mongo::GlobalInitializerRegisterer::GlobalInitializerRegisterer(std::string const&, boost::function<mongo::Status (mongo::InitializerContext*)> const&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&) (/local/mt1/workspace/example-third/build/libAccessop.so)
    at  (/local/mt1/workspace/example-third/build/libAccessop.so)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib/x86_64-linux-gnu/libdl.so.2)
    at  (/lib64/ld-linux-x86-64.so.2)
    at  (/lib/x86_64-linux-gnu/libdl.so.2)
    at dlopen (/lib/x86_64-linux-gnu/libdl.so.2)
...
 
The code that is a source of this exception is available at:
https://github.com/mongodb/mongo-perf/blob/master/mongo-cxx-driver/src/mongo/base/global_initializer_registerer.cpp

Does anyone have an idea what could be the reason of this exception appearing? Status value says nothing much constructive...

Eric Milkie

unread,
May 23, 2013, 8:48:24 AM5/23/13
to mongod...@googlegroups.com

The error means that the global constructor (which registers something in a map) ran twice.  That's why the error is DuplicateKey.  You might be linking in the library twice.
We are working on making a C++ driver shared library that works properly; it will make doing something like this much easier.  



Paweł Skorupiński

unread,
May 23, 2013, 10:28:21 AM5/23/13
to mongod...@googlegroups.com
Eric, your explanation makes sense. Actually, I do not know why it would be linked twice but I am not a compiling/linking master, so it might be just happening.

Please, tell me one more thing. As I mentioned, I have changed SConfigure by adding -fPIC flag. I could try right now to make shared object mongoclient.so out of my mongoclient.a using g++ (when I did this on 32-bit system, it worked correctly). You do not expect it to work properly?
Reply all
Reply to author
Forward
0 new messages