From 964efd2d7aff7ddca6c27691fb289665348e6494 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Sun, 29 Aug 2021 01:03:56 +0300 Subject: [PATCH] [#2061] fixed TSAN warnings in kea-netconf --- src/bin/netconf/netconf_process.cc | 33 ++++++---------------- src/bin/netconf/tests/netconf_unittests.cc | 22 +++++++-------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/bin/netconf/netconf_process.cc b/src/bin/netconf/netconf_process.cc index 62cbdb23ae..ef1672b119 100644 --- a/src/bin/netconf/netconf_process.cc +++ b/src/bin/netconf/netconf_process.cc @@ -40,30 +40,15 @@ NetconfProcess::run() { LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION); try { - // Initialize netconf agent in a thread. - std::thread th([this]() { - try { - // Initialize sysrepo. - agent_.initSysrepo(); - - // Get the configuration manager. - NetconfCfgMgrPtr cfg_mgr(getNetconfCfgMgr()); - - // Call init. - agent_.init(cfg_mgr); - } catch (...) { - // Should not happen but in case... - std::exception_ptr eptr = std::current_exception(); - getIoService()->post([eptr] () { - if (eptr) { - std::rethrow_exception(eptr); - } - }); - } - }); - - // Detach the thread. - th.detach(); + // Initialize netconf agent. + // Initialize sysrepo. + agent_.initSysrepo(); + + // Get the configuration manager. + NetconfCfgMgrPtr cfg_mgr(getNetconfCfgMgr()); + + // Call init. + agent_.init(cfg_mgr); // Let's process incoming data or expiring timers in a loop until // shutdown condition is detected. diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index 76419328c0..bd9be00f42 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -187,31 +187,28 @@ class NetconfAgentLogTest : public dhcp::test::LogContentTest { public: /// @brief Constructor. NetconfAgentLogTest() - : io_service_(new IOService()), + : finished_(false), + io_service_(new IOService()), thread_(), agent_(new NakedNetconfAgent) { } /// @brief Destructor. virtual ~NetconfAgentLogTest() { + if (agent_) { + clearYang(agent_); + agent_->clear(); + } + agent_.reset(); // io_service must be stopped to make the thread to return. io_service_->stop(); - io_service_.reset(); if (thread_) { thread_->join(); thread_.reset(); } - if (agent_) { - clearYang(agent_); - agent_->clear(); - } - agent_.reset(); + io_service_.reset(); } - - /// @brief To know when the callback was called. - bool finished_; - /// @brief Default change callback (print changes and return OK). sr_error_t callback(sysrepo::S_Session sess, const char* module_name, @@ -233,6 +230,9 @@ public: } } + /// @brief To know when the callback was called. + std::atomic finished_; + /// @brief IOService object. IOServicePtr io_service_; -- 2.47.3