[CXX-456] Why can't driver connect? Created: 22/Dec/14  Updated: 11/Sep/19  Resolved: 16/Jan/15

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

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

Linux (Fedora 21)



 Description   

Hi.
I'm having some strange problems with the C++ driver. I have been digging for some time.
I'm programming against Fedora 21's libmongoclient (2.4.9) and it works. But since I'm deploying to Amazon I need to compile statically so I clone from mongo-cxx-driver. This worked fine last week, but today I pulled the latest rc3 and now I can't even get the hello world app to work (slightly modified):

#include <cstdlib>
#include <iostream>
#include <string>
#include "mongo/client/dbclient.h" // for the driver
using namespace std;
 
void run() {
    mongo::DBClientConnection c;
    string host = "127.0.0.1";
    mongo::HostAndPort hp(host, 27017);
    string err;
    c.connect(hp, err);
}
 
int main() {
    mongo::client::initialize();
    try
        { run(); std::cout << "connected ok" << std::endl; }
    catch( const mongo::DBException &e )
        { std::cout << "caught " << e.what() << std::endl; }
    return EXIT_SUCCESS;
}

This code, and my fails to connect and throws this exception:

caught DBClientBase::findN: transport error: 127.0.0.1:27017 ns: admin.$cmd query: { ismaster: 1 }

I tried resetting to rc2 and that revision actually connects without exceptions and I can download a BSONObject, however - this version just returns EOO for fields that actually exists (I can see them in Robomongo and the whole program works with Fedora's libmongoclient).
But since I cannot even get the hello world sample to work something has to be wrong.

I'm compiling with:
sudo scons --prefix=/usr --ssl -j 8 install

And I'm cloning with:
git clone https://github.com/mongodb/mongo-cxx-driver.git



 Comments   
Comment by Andrew Morrow (Inactive) [ 16/Jan/15 ]

Hi Alex -

I'm closing this ticket since I haven't heard back from you. Please feel free to re-open it if you are still having difficulties.

Thanks,
Andrew

Comment by Andrew Morrow (Inactive) [ 14/Jan/15 ]

Hi alexhultman -

I wanted to check in with you on the status of this ticket. Were you able to gather any more information that might help us reproduce this issue?

Thanks,
Andrew

Comment by Andrew Morrow (Inactive) [ 03/Jan/15 ]

Hi Alex -

OK, please let us know what you find out when you are back at work. As I mentioned earlier the GA is coming up (around the end of the month), so of course we are interested in ensuring that the current RC works correctly on Fedora 21. We appreciate your help testing the RCs.

Thanks,
Andrew

Comment by Alex Hultman [ 03/Jan/15 ]

Hi. Sorry for the delays. New year and stuff. Work begins jan 7 again. But you are probably right, there can be something with my install path. I get that I need to compile the app with the same headers that I compiled the driver with but I thought existing headers if any would be overwritten. I'll experiment more when I get back. 0.9.0 works for me right now though.

Comment by Andrew Morrow (Inactive) [ 02/Jan/15 ]

Hi Alex -

Were you able to make any progress on your side with this issue? Without some additional information leading to a local reproduction it is difficult to make much progress.

Thanks,
Andrew

Comment by Andrew Morrow (Inactive) [ 30/Dec/14 ]

Hi Alex -

To add to the above, I'm running mongod 2.6.6 installed from the official mongodb repository:

$ sudo yum list installed | grep mongod
mongodb-org.x86_64                   2.6.6-1                    @mongodb
mongodb-org-mongos.x86_64            2.6.6-1                    @mongodb
mongodb-org-server.x86_64            2.6.6-1                    @mongodb
mongodb-org-shell.x86_64             2.6.6-1                    @mongodb
mongodb-org-tools.x86_64             2.6.6-1                    @mongodb

Note that I do not have any of the libmongodb packages installed. I have mongod running as a service:

$ systemctl status mongod.service
● mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod)
   Active: active (running) since Tue 2014-12-16 22:24:04 UTC; 1 weeks 6 days ago
  Process: 5539 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=0/SUCCESS)
 Main PID: 5554 (mongod)
   CGroup: /system.slice/mongod.service
           └─5554 /usr/bin/mongod -f /etc/mongod.conf

Please note that in Fedora 21 the SELinux aspect of Fedora now defaults to 'Enforcing' mode, so this machine has been reconfigured to allow mongod to run in such an environment.

Comment by Andrew Morrow (Inactive) [ 30/Dec/14 ]

Hi Alex -

I cannot reproduce your issue on a Fedora 21 machine. I compiled -rc3 from source and installed to $HOME/opt:

$ git clone https://github.com/mongodb/mongo-cxx-driver.git
$ cd mongo-cxx-driver
$ git checkout legacy-1.0.0-rc3
$ scons --prefix=$HOME/opt --ssl -j 8 install

I then built your example against my installed copy of the library:

$ cat ./CXX-456.cpp
#include <cstdlib>
#include <iostream>
#include <string>
#include "mongo/client/dbclient.h" // for the driver
using namespace std;
 
void run() {
    mongo::DBClientConnection c;
    string host = "127.0.0.1";
    mongo::HostAndPort hp(host, 27017);
    string err;
    c.connect(hp, err);
}
 
int main() {
    mongo::client::initialize();
    try
        { run(); std::cout << "connected ok" << std::endl; }
    catch( const mongo::DBException &e )
        { std::cout << "caught " << e.what() << std::endl; }
    return EXIT_SUCCESS;
}
$ g++ -pthread ./CXX-456.cpp -I $HOME/opt/include -L $HOME/opt/lib -lmongoclient -lboost_regex -lboost_system -lboost_thread -lcrypto -lssl
$ ./a.out
connected ok

The program runs correctly.

Comment by Andrew Morrow (Inactive) [ 30/Dec/14 ]

OK. Since we are hoping to issue a GA soon, we would like to understand why -rc3 doesn't work for you. One thing I notice is that you are installing with a prefix of /usr.

Potentially, this could conflict with the existing mongo client driver package installation artifacts.

Could you try uninstalling all mongo packages, and building the -rc3 driver to somewhere non-standard ($HOME/opt for instance). Then see if your program compiled and linked against those headers and libs works better. Obviously, you will need to have mongod not-from-packages running somewhere.

Thanks,
Andrew

Comment by Alex Hultman [ 29/Dec/14 ]

Sorry for the ambiguity. libmongodb-devel installs libmongoclient.so, which works. When compiling rc3, rc2, rc1, rc0 I get various problems. However currently I have settled for 0.9.0 since that specific version works without any problems.

I tried to download and run mongod 2.6.6 and it runs well, but doesnt change anything. I dont use any SSL.

Comment by Andrew Morrow (Inactive) [ 29/Dec/14 ]

Hi Alex -

It seems as if there are several versions of both the server and driver in play here, so it is somewhat unclear exactly what is going wrong. Can you clarify a few things for me:

  • What Fedora 21 package did you install to obtain the libmongoclient.so file?
  • You said that you "tried running mongod 2.6.6 downloaded from mongodb.org and it doesn't work". When you say it didn't work, do you mean that 2.6.6 mongod didn't work? Or do you mean that you had the same issue with the driver when you upgraded the server to 2.6.6?

Thanks,
Andrew

Comment by Alex Hultman [ 23/Dec/14 ]

Fedora 21 seems to come with MongoDB 2.4.9.

mongod is run without SSL. My mongod doesn't support --sslMode

Mongo shell works, Robomongo (GUI) lists everything correctly. I can't get the hello world to run with setSSLMode.

What version of mongod do you use?

Edit:

Using mongo::client::Options::kSSLDisabled doesn't work either.

I tried running mongod 2.6.6 downloaded from mongodb.org and it doesn't work.

Comment by Tyler Brock [ 22/Dec/14 ]

Is the mongod you are trying to connect to started with SSL required?

If so you need to enable SSL in the driver:

int main() {
    mongo::client::Options opts;
    opts.setSSLMode(mongo::client::Options::kSSLRequired);
    mongo::client::initialize(opts);
    ...
}

Also, if that does not work for you can you confirm that you can connect via the shell?

I've had your test program run successfully using the latest driver by making the above modifications to your program and starting my mongod with the following command:

 mongod --sslMode requireSSL --sslPEMKeyFile ./jstests/libs/server.pem 

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