Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10427

segfault when calling mongo::ScopedDbConnection::getScopedDbConnection(connection_string) with replicaset

    XMLWordPrintable

    Details

    • Operating System:
      Linux
    • Steps To Reproduce:
      Hide

      With a little of bad luck - or Redhat (?) -, this code is sufficient.

        // conn_str like: rs-name/host1:1001,host2:1001,host3:1001
        // I tried to replace hostnames with IP but it does not help
       
        std::string errors;
        const auto cs = mongo::ConnectionString::parse(conn_str, errors);
        if (! cs.isValid() )
        {
          return false;
        }
       
        // here I keep the default socketTimeout=0
        auto conn_ptr = mongo::ScopedDbConnection::getScopedDbConnection(cs); // line 137, segfault

      Show
      With a little of bad luck - or Redhat (?) -, this code is sufficient. // conn_str like: rs-name/host1:1001,host2:1001,host3:1001 // I tried to replace hostnames with IP but it does not help   std::string errors; const auto cs = mongo::ConnectionString::parse(conn_str, errors); if (! cs.isValid() ) { return false; }   // here I keep the default socketTimeout=0 auto conn_ptr = mongo::ScopedDbConnection::getScopedDbConnection(cs); // line 137, segfault

      Description

      Hi,

      as a surprise I suffer from a segfault when I connect to a replicaset of MongoDB 2.4.3 with C++ driver 2.4.1. RS consists of 1 master and 2 slaves.

      The surprise comes from the fact that exactly the same code works well in most environments (Ubuntu, Redhat) and even in the above environment (Redhat) in another application against the same replicaset.

      Code (executed in a lambda):

        // conn_str like: rs-name/host1:1001,host2:1001,host3:1001
        // I tried to replace hostnames with IP but it does not help
       
        std::string errors;
        const auto cs = mongo::ConnectionString::parse(conn_str, errors);
        if (! cs.isValid() )
        {
          return false;
        }
       
        // here I keep the default socketTimeout=0
        auto conn_ptr = mongo::ScopedDbConnection::getScopedDbConnection(cs); // line 137, segfault

      Stacktrace:

      #0  0x00007ffff7b20d3d in inet_pton () from ~/mdbtest-pkg/lib/libc-2.15.so
      #1  0x00007ffff7ae8e10 in ?? () from ~/mdbtest-pkg/lib/libc-2.15.so
      #2  0x00007ffff7aec99e in getaddrinfo () from ~/mdbtest-pkg/lib/libc-2.15.so
      #3  0x000000000190008a in mongo::SockAddr::SockAddr(char const*, int) ()
      #4  0x00000000018adadb in mongo::DBClientConnection::_connect(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
      #5  0x00000000018adeb4 in mongo::DBClientConnection::connect(mongo::HostAndPort const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
      #6  0x00000000018ab8f0 in mongo::ConnectionString::connect(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, double) const ()
      #7  0x00000000018c5313 in mongo::ReplicaSetMonitor::_populateHosts_inSetsLock(std::vector<mongo::HostAndPort, std::allocator<mongo::HostAndPort> > const&) ()
      #8  0x00000000018c5996 in mongo::ReplicaSetMonitor::ReplicaSetMonitor(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<mongo::HostAndPort, std::allocator<mongo::HostAndPort> > const&) ()
      #9  0x00000000018c657b in mongo::ReplicaSetMonitor::createIfNeeded(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<mongo::HostAndPort, std::allocator<mongo::HostAndPort> > const&) ()
      #10 0x00000000018c6726 in mongo::DBClientReplicaSet::DBClientReplicaSet(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<mongo::HostAndPort, std::allocator<mongo::HostAndPort> > const&, double) ()
      #11 0x00000000018ab935 in mongo::ConnectionString::connect(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, double) const ()
      #12 0x00000000018a7814 in mongo::DBConnectionPool::get(mongo::ConnectionString const&, double) ()
      #13 0x00000000018a4be7 in mongo::ScopedDbConnection::getScopedDbConnection(mongo::ConnectionString const&, double) ()
      #14 0x0000000000f67ebe in operator() (__closure=<value optimized out>) at persistermdb.cpp:137
      #15 0x0000000000f67ff1 in _Function_handler<bool, PersisterMDB::connect()::<lambda()> >::_M_invoke(const _Any_data &) (
          __functor=<value optimized out>) at /opt/c1/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/functional:1912
      [...]

      You may note the libc-2.15 which I LD_PRELOAD because the test machine has another libc version than the build machine. Both application and driver are built against libc-2.15 of course and the preload does work well with other app which uses exactly the same code.

      Any hints appreciated.

      Cheers
      Ingo

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: