From 4dc7a5ca0aa5dfed57a08cc112e57736dc0334a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Fri, 16 Apr 2021 15:54:45 -0400
Subject: [PATCH] dhtrunner: log warning if calling run() while already running

---
 src/dhtrunner.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp
index 2a5ffc06..576d3304 100644
--- a/src/dhtrunner.cpp
+++ b/src/dhtrunner.cpp
@@ -104,8 +104,11 @@ DhtRunner::run(const Config& config, Context&& context)
 {
     std::lock_guard<std::mutex> lck(dht_mtx);
     auto expected = State::Idle;
-    if (not running.compare_exchange_strong(expected, State::Running))
+    if (not running.compare_exchange_strong(expected, State::Running)) {
+        if (context.logger)
+            context.logger->w("[runner %p] Node is already running. Call join() first before calling run() again.");
         return;
+    }
 
     auto local4 = config.bind4;
     auto local6 = config.bind6;
-- 
GitLab