diff --git a/src/dht.cpp b/src/dht.cpp
index bbd2b958213ab0f49a4a41d9f2245e16debd7634..331e418b745b5a5a4706cf08318ff662eb87c270 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -1984,10 +1984,10 @@ Dht::onConnected()
         bootstrapJob.reset();
     }
     bootstrap_period = std::chrono::seconds(10);
-    while (not onConnectCallbacks_.empty()) {
-        auto cb = std::move(onConnectCallbacks_.front());
-        onConnectCallbacks_.pop();
-        cb();
+    auto callbacks = std::move(onConnectCallbacks_);
+    while (not callbacks.empty()) {
+        callbacks.front()();
+        callbacks.pop();
     }
 }
 
diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp
index ab7b86cd2409be09682a4c0d2d2764aea242683e..60cd50d5221c410b2d9fd78e40cd395b096a1796 100644
--- a/src/dht_proxy_client.cpp
+++ b/src/dht_proxy_client.cpp
@@ -727,9 +727,8 @@ DhtProxyClient::onProxyInfos(const Json::Value& proxyInfos, const sa_family_t fa
                 std::lock_guard<std::mutex> lock(lockCallbacks_);
                 callbacks_.emplace_back([cbs = std::move(onConnectCallbacks_)]() mutable {
                     while (not cbs.empty()) {
-                        auto cb = std::move(cbs.front());
+                        cbs.front()();
                         cbs.pop();
-                        cb();
                     }
                 });
             }