Uploaded image for project: 'MariaDB Connector/C++'
  1. MariaDB Connector/C++
  2. CONCPP-105

Connector crashes when attempting connections from multiple threads

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 1.0.1, 1.1.1
    • 1.0.2, 1.1.2
    • General
    • None

    Description

      This is based of stackoverflow question
      It looks like an issue in the connector. Some comments suggest there is the race condition

      The standalone testcase(from the same source)

      #include <mariadb/conncpp.hpp>
      #include <iostream>
      #include <thread>
      #include <string>
       
      sql::Driver* driver = sql::mariadb::get_driver_instance();
      sql::SQLString connectionUrl = "jdbc:mariadb://localhost:3306/the_database_name";
      sql::Properties properties = {{"user", "the_username"}, {"password", "the_password"}};
       
      int main()
      {
          // simulate 2 concurrent connections each making 500 requests
          std::vector<std::function<void()>> t1cbs;
          std::vector<std::function<void()>> t2cbs;
          for(int i = 0; i < 500; i++) // if does not fail for you at 500 up the number until it does
          {
              t1cbs.push_back([&]{
                  std::unique_ptr<sql::Connection> conn(driver->connect(connectionUrl, properties));
                  std::cout << "t1:" << conn->getHostname().c_str() << std::endl;
              });
       
              // comment out this block to keep the second thread from executing, and you will see 
              // that no errors occur
              t2cbs.push_back([&]{
                  std::unique_ptr<sql::Connection> conn(driver->connect(connectionUrl, properties));
                  std::cout << "t2:" << conn->getHostname().c_str() << std::endl;
              });
          }
       
          std::thread t1([&]{
              for(auto& cb : t1cbs)
                  cb();
          });
       
          std::thread t2([&]{
              for(auto& cb : t2cbs)
                  cb();
          });
       
          t1.join();
          t2.join();
       
          return 0;
      }
      

      Attachments

        Activity

          People

            Lawrin Lawrin Novitsky
            Lawrin Lawrin Novitsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.