[CXX-570] Auth() function cause core dump in shared library - fcgi environment Created: 27/Mar/15  Updated: 11/Sep/19  Resolved: 31/Mar/15

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

Type: Task Priority: Major - P3
Reporter: Fanky Assignee: Unassigned
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

RHEL6 x64


Attachments: HTML File example    

 Description   

Here's my case:
I upgrade mongo server to 2.6 from 2.4, after that I upgrade user authorization data to 2.6 too.
Then I build c++ legacy-1.0.0 driver on my system which has 2 RHEL6 machine (a 2 nodes replicaset).
I write a c++ function to connect, authenticate, query again a collection.
The function works well when I run it as standalone c++ application. Then I build a shared library and call this function from fcgi application (using dlopen), my fcgi dump at driver's auth api.
I attach the function below.
I can't debug or explain that, just don't know how it happened, please help me.
Thank in advance!



 Comments   
Comment by Fanky [ 30/Mar/15 ]

Hi Andrew,

I've moved the GlobalInstance to main() section and it is ok now.

Thanks for your support!

Comment by Andrew Morrow (Inactive) [ 29/Mar/15 ]

Hi -

Thank you for the bug report.

The example you provided cannot be compiled as-is. If possible, could you provide a complete, compilable example program that demonstrates the crash?

If that is not possible, then providing a stack trace would also be helpful. You should be able to obtain a stack trace from the corefile by loading your application and the corefile in GDB and invoking 'thread apply all bt'.

However, based on the code you provided, I have a few immediate observations:

  • You are not checking that initialization succeeded. In particular, you are required to invoke one of the 'status', 'initialized', or 'assertInitialized' methods on GlobalInstance after constructing one to ensure that the driver was correctly initialized.
  • There is a self contradiction in your code: The 'Insert' function takes a BSONObj object by value. However, you are required to have initialized the driver before constructing an BSONObj objects. But then the 'Insert' function appears to be trying to initialize the driver. So, at best, this subsequent attempt to initialize the driver is redundant, or, at worst, it indicates that initialization of the driver is being done too late.
  • Finally, note that your application will only ever support one call to 'Insert'. Subsequent calls to 'Insert' will not work correctly, because the driver will be destroyed when the GlobalInstance goes out of scope.

My suggestion is that you try moving the GlobalInstance variable to some common startup section of your FastCGI program.

Thanks,
Andrew

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