]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2061] fixed TSAN warnings in kea-netconf
authorRazvan Becheriu <razvan@isc.org>
Sat, 28 Aug 2021 22:03:56 +0000 (01:03 +0300)
committerRazvan Becheriu <razvan@isc.org>
Sat, 28 Aug 2021 22:18:07 +0000 (01:18 +0300)
src/bin/netconf/netconf_process.cc
src/bin/netconf/tests/netconf_unittests.cc

index 62cbdb23ae8809e78108cc82443a0d90652fa516..ef1672b1198536da9face216a7686fc3409fc376 100644 (file)
@@ -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.
index 76419328c04d1f50951a7e0b2751202e5aedfbad..bd9be00f42ce2be23369e56e972b47d01b66fc43 100644 (file)
@@ -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<bool> finished_;
+
     /// @brief IOService object.
     IOServicePtr io_service_;