[CXX-324] Static initialization of mongo::DBClientConnection Created: 01/Sep/14  Updated: 23/Oct/14  Resolved: 09/Sep/14

Status: Closed
Project: C++ Driver
Component/s: Testing
Affects Version/s: legacy-1.0.0-rc0
Fix Version/s: legacy-1.0.0-rc1

Type: Bug Priority: Major - P3
Reporter: Artyom Assignee: Tyler Brock
Resolution: Won't Fix Votes: 0
Labels: crash, driver, legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello.
I'm using static instance of a class like this one:
class Storage {
private:
mongo::DBClientConnection _db;
};

At the beginning of my program execution I got an Segmentation fault exception in std::string::assign, raised from here:
_writeConcern = WriteConcern::acknowledged; (dbclient.cpp:1460).

As the order of initialization of global and static variables are undefined I imply that static instance of
static const WriteConcern acknowledged;
hadn't been initialized at this moment.
I've changed this line to
_writeConcern = WriteConcern();
and it solved the problem for me.

Compiler: g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1, --c++11=on



 Comments   
Comment by Githook User [ 09/Sep/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: Revert "CXX-324 do not depend on static init for WriteConcern"

This reverts commit aadc8d081511d96e05cf8e819203d0593b276c4f.
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/e55e0f2a1e6ad30033e876a5f236be4697a64339

Comment by Githook User [ 09/Sep/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: Revert "CXX-324 fix additional tests"

This reverts commit 211b1f49f7ec9adaf1419d075b05d9d0404e12f0.
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/a2d18f25dbb2f0fbdd3e0e04cbca6da7a8696d7f

Comment by Tyler Brock [ 09/Sep/14 ]

Hey Artyom, unfortunately we had to re-think this one and revert it. The C++ driver cannot be used before mongo::client::initialize() has been invoked so users of the driver cannot and should not have static objects that use the driver in any way before entering main (presumably where initialize is called).

Comment by Githook User [ 03/Sep/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-324 fix additional tests
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/211b1f49f7ec9adaf1419d075b05d9d0404e12f0

Comment by Githook User [ 03/Sep/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-324 do not depend on static init for WriteConcern
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/aadc8d081511d96e05cf8e819203d0593b276c4f

Comment by Tyler Brock [ 03/Sep/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/146

Comment by Tyler Brock [ 01/Sep/14 ]

Hey Artyom, thanks for filing the ticket. I am going to take a look tomorrow but it sounds like you are correct and that this should be fixed.

Generated at Wed Feb 07 21:58:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.