From: Marcin Siodelski Date: Thu, 18 Aug 2016 10:22:54 +0000 (+0200) Subject: [4544] Prevent unexpected closing of connection to the host database. X-Git-Tag: trac4631_base~23^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b7b75e4b00270d9a0729c40ca44df3f8be176fd7;p=thirdparty%2Fkea.git [4544] Prevent unexpected closing of connection to the host database. --- diff --git a/src/lib/dhcpsrv/cfg_db_access.cc b/src/lib/dhcpsrv/cfg_db_access.cc index 571ae18ff0..4601dc93e6 100644 --- a/src/lib/dhcpsrv/cfg_db_access.cc +++ b/src/lib/dhcpsrv/cfg_db_access.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,7 @@ CfgDbAccess::createManagers() const { // Recreate host data source. HostDataSourceFactory::destroy(); if (!host_db_access_.empty()) { - HostDataSourceFactory::create(getHostDbAccessString()); + HostMgr::create(getHostDbAccessString()); } } diff --git a/src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc b/src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc index 49d3a378ff..03523d34b0 100644 --- a/src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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()); }); }