Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-2652

Get a coredump when building with g++73

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Summary

      Got a coredump when compile with a high version g+. eg: g+73

       

      here is the test code.

      // code placeholder
      // Copyright 2016 MongoDB Inc.
      //
      // Licensed under the Apache License, Version 2.0 (the "License");
      // you may not use this file except in compliance with the License.
      // You may obtain a copy of the License at
      //
      // http://www.apache.org/licenses/LICENSE-2.0
      //
      // Unless required by applicable law or agreed to in writing, software
      // distributed under the License is distributed on an "AS IS" BASIS,
      // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      // See the License for the specific language governing permissions and
      // limitations under the License.#include <cstdlib>
      #include <memory>#include <bsoncxx/builder/basic/array.hpp>
      #include <bsoncxx/builder/basic/document.hpp>
      #include <bsoncxx/builder/basic/kvp.hpp>
      #include <bsoncxx/json.hpp>
      #include <bsoncxx/stdx/make_unique.hpp>
      #include <bsoncxx/string/to_string.hpp>
      #include <bsoncxx/types.hpp>#include <bsoncxx/stdx/make_unique.hpp>
      #include <bsoncxx/stdx/optional.hpp>
      #include <bsoncxx/stdx/string_view.hpp>
      #include <mongocxx/instance.hpp>
      #include <mongocxx/logger.hpp>
      #include <mongocxx/pool.hpp>
      #include <mongocxx/uri.hpp>
      #include <mongocxx/client.hpp>using bsoncxx::builder::basic::kvp;
      using bsoncxx::builder::basic::make_array;
      using bsoncxx::builder::basic::make_document;namespace {// The mongocxx::instance constructor and destructor initialize and shut down the driver,
      // respectively. Therefore, a mongocxx::instance must be created before using the driver and
      // must remain alive for as long as the driver is in use.
      //
      // This example demonstrates how one might keep a heap allocated mongocxx::instance and
      // mongocxx::pool object associated in a way that allows dynamic configuration. Most of the examples
      // simply create a stack allocated mongocxx::instance object, which is fine for small examples, but
      // real programs will typically require shared access to a commonly configured instance and
      // connection pool across different translation units and components. By providing a singleton which
      // owns the instance and pool objects, we can defer configuration until we are ready to use MongoDB,
      // and share the instance and pool objects between multiple functions.class mongo_access {
         public:
          static mongo_access& instance() {
              static mongo_access instance;
              return instance;
          }    void configure(std::unique_ptr<mongocxx::instance> instance,
                         std::unique_ptr<mongocxx::pool> pool) {
              _instance = std::move(instance);
              _pool = std::move(pool);
          }    using connection = mongocxx::pool::entry;    connection get_connection() {
              return _pool->acquire();
          }    bsoncxx::stdx::optional<connection> try_get_connection() {
              return _pool->try_acquire();
          }   private:
          mongo_access() = default;    std::unique_ptr<mongocxx::instance> _instance = nullptr;
          std::unique_ptr<mongocxx::pool> _pool = nullptr;
      };}  // namespace// The 'configure' and 'do_work' functions use the same mongocxx::instance and mongocxx::pool
      // objects by way of the mongo_access singleton.void configure(mongocxx::uri uri) {
          class noop_logger : public mongocxx::logger {
             public:
              virtual void operator()(mongocxx::log_level,
                                      bsoncxx::stdx::string_view,
                                      bsoncxx::stdx::string_view) noexcept {}
          };    auto instance =
              bsoncxx::stdx::make_unique<mongocxx::instance>(bsoncxx::stdx::make_unique<noop_logger>());    mongo_access::instance().configure(std::move(instance),
                                             bsoncxx::stdx::make_unique<mongocxx::pool>(std::move(uri)));
      }bool do_work() {
          auto conn = mongo_access::instance().get_connection();
          if (!conn)
              return false;
          
          auto db = (*conn)["session_db"];
          auto collection = db["dddd"];    return true;
      }int main(int argc, char* argv[]) {
          auto uri = mongocxx::uri{(argc >= 2) ? argv[1] : mongocxx::uri::k_default_uri};
          configure(std::move(uri));
          do_work();
          return EXIT_SUCCESS;
       
       
       
       
      
      

       

       

      Coredump

      Environment

      Please provide the version of the C / CXX driver.

      mongo-cxx-driver-r3.7.0

       

      Please provide the host OS, version, and architecture (example: Windows 10 64-bit x86).

      Linux 9.134.1.187 3.10.107-1-tlinux2_kvm_guest-0056 #1 SMP Wed Dec 29 14:35:09 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

       

      Please provide the C / CXX compiler and version.

      g++ : g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)

      g+73: g+73 (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

       

      If applicable, please attach the full output of the cmake command used to configure the C / CXX driver.

      If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      compile the code with g++ version 4.8.5 , all things are OK, no coredump.

      but when compiling with g++73, mongo_test would get a coredump.

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

      Attachments

        1. mongo_test.cpp
          4 kB
        2. yyyyy.png
          yyyyy.png
          571 kB

        Activity

          People

            kevin.albertson@mongodb.com Kevin Albertson
            firewiki2022@gmail.com wiki fire
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: