]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4544] Prevent unexpected closing of connection to the host database.
authorMarcin Siodelski <marcin@isc.org>
Thu, 18 Aug 2016 10:22:54 +0000 (12:22 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 18 Aug 2016 10:22:54 +0000 (12:22 +0200)
src/lib/dhcpsrv/cfg_db_access.cc
src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc

index 571ae18ff04783c63d0ad494dc2dc41c17fb122d..4601dc93e62ba6ae5e2e4b91780887bd6b21ab22 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <sstream>
 
@@ -39,7 +40,7 @@ CfgDbAccess::createManagers() const {
     // Recreate host data source.
     HostDataSourceFactory::destroy();
     if (!host_db_access_.empty()) {
-        HostDataSourceFactory::create(getHostDbAccessString());
+        HostMgr::create(getHostDbAccessString());
     }
 }
 
index 49d3a378ff9535b51ca737d14266cbdef7215218..03523d34b077b7c168dfdc44c698e95621d80925 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/mysql_schema.h>
@@ -108,6 +109,20 @@ TEST_F(CfgMySQLDbAccessTest, createManagers) {
     ASSERT_NO_THROW({
         HostDataSourcePtr& host_data_source =
             HostDataSourceFactory::getHostDataSourcePtr();
+        ASSERT_TRUE(host_data_source);
+        EXPECT_EQ("mysql", host_data_source->getType());
+    });
+
+    // Because of the lazy initialization of the HostMgr instance, it is
+    // possible that the first call to the instance() function tosses
+    // existing connection to the database created by the call to
+    // createManagers(). Let's make sure that this doesn't happen.
+    ASSERT_NO_THROW(HostMgr::instance());
+
+    ASSERT_NO_THROW({
+        HostDataSourcePtr& host_data_source =
+            HostDataSourceFactory::getHostDataSourcePtr();
+        ASSERT_TRUE(host_data_source);
         EXPECT_EQ("mysql", host_data_source->getType());
     });
 }