[CXX-564] getLastError() fail randomly Created: 19/Mar/15  Updated: 23/Mar/15  Resolved: 23/Mar/15

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: legacy-1.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Judy Han [X] Assignee: Adam Midvidy
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I have an application - a threadpool with each worker thread maintaining it's own connection, after insert (bulk) the subsequent getLastError() call randomly fail. Here is the relavant code snippet for each worker thread:
static _thread mongo::DBClientConnection *mongoPtr;
...
bool event_loader::threadSpecificInit()

{ //each thread call this once at thread startup mongoPtr_ = new mongo::DBClientConnection(); ...}

void event_loader::handleInput() {
//each thread run this in a loop
try {
//build bulk_data
......
mongoPtr_->insert("event_test.collection1", bulk_data);
if (!(mongoPtr_->getLastError()).empty())

{ std::cout << "insert failed" << std::endl; }

catch (const MtxUtil::Exception& exc)

{ std::cout << "Caught an exception during getLastError.\n" << "Exception's what()=" << exc.what() << std::endl; }

catch (...)

{ std::cout << "Caught an unknown exception during getLastError." << std::endl; }

Without calling getLastError(), the program seems works fine. After adding getLastError() logic, the program works sometimes, but fails some other time, once it fails it continues to fail.

Following is the output for failed case:
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.
Caught an unknown exception during getLastError.



 Comments   
Comment by Adam Midvidy [ 23/Mar/15 ]

Hi Judy,

Sure. I will close the ticket as "Gone Away". Feel free to reopen if you are able to reproduce this again.

Best,
Adam

Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam,

Thanks. Since the problem was sporadic, it is not so easy to say it is completely fixed.
I was able to reproduce the problem only once (the first try after recompile) and the case is a bit different from before - this time I had other errors during the test. But I am not able to reproduce it.
Maybe we can close this ticket for now and re-open it later if I see that again?

Thanks!
Judy

Comment by Adam Midvidy [ 23/Mar/15 ]

Hey Judy,

Would you mind rerunning your test now that you have the driver compiling with C++11 mode? There is a possibility that this issue was caused by linking ABI incompatible libstdc++ versions, which can cause strange crashes/bugs.

Adam

Comment by Judy Han [X] [ 19/Mar/15 ]

Hi Adam,
Thanks! yes the Scons invocation used to compile the driver is the same as CXX-565. The command line options are similar except that we use some extra libraries -lace -lrt -ldl -lxercesc.
Judy

Comment by Adam Midvidy [ 19/Mar/15 ]

Hi Judy,

Thanks for the report. I will try to reproduce this issue today.

Can I have the exact SCons invocation used to compile the driver, as well as the compiler flags used to build your application? If they are the same as in CXX-565, you can just indicate that as well.

Adam

Comment by Judy Han [X] [ 19/Mar/15 ]

fixing some typo, add line number for easier reference for the code snippet:
1 static _thread mongo::DBClientConnection *mongoPtr;
2 ...
3 bool event_loader::threadSpecificInit()
4

{ //each thread call this once at thread startup mongoPtr_ = new mongo::DBClientConnection(); ...}

5
6 void event_loader::handleInput() {
7 //each thread run this in a loop
8 try {
9 //build bulk_data
10 ......
11 mongoPtr_->insert("event_test.collection1", bulk_data);
12 try {
13 if (!(mongoPtr_->getLastError()).empty())
14

{ std::cout << "insert failed" << std::endl; }

15 }
16 catch (const MtxUtil::Exception& exc)
17

{ std::cout << "Caught an exception during getLastError.\n" << "Exception's what()=" << exc.what() < < std::endl; }

18
19 catch (...)
20

{ std::cout << "Caught an unknown exception during getLastError." << std::endl; }


21 ...
22 }
23 catch (const MtxUtil::Exception& exc)
24 ...
25 }
~

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