]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 30 Jul 2025 23:12:23 +0000 (09:12 +1000)
committerPrashant D <pdhange@redhat.com>
Wed, 10 Sep 2025 01:27:52 +0000 (21:27 -0400)
Calling back into python functions whilst holding the lock can result in
this thread being queued for the GIL and resulting in extended delays
for threads waiting to acquire the lock.

Fixes: https://tracker.ceph.com/issues/72337
Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
(cherry picked from commit b4304d521f61b61515cade872824210e7d67f6db)

src/mgr/DaemonState.h

index 0688db81bb1f60dc4407646b1055810bd892b642..7fc630fbf7f3772a56ab905d3b8bf7c1e22fd9c0 100644 (file)
@@ -260,9 +260,12 @@ public:
   template<typename Callback, typename...Args>
   auto with_daemons_by_server(Callback&& cb, Args&&... args) const ->
     decltype(cb(by_server, std::forward<Args>(args)...)) {
-    std::shared_lock l{lock};
-    
-    return std::forward<Callback>(cb)(by_server, std::forward<Args>(args)...);
+    const decltype(by_server) by_server_copy = [&] {
+      // Don't hold the lock any longer than necessary
+      std::shared_lock l{lock};
+      return by_server;
+    }();
+    return std::forward<Callback>(cb)(by_server_copy, std::forward<Args>(args)...);
   }
 
   template<typename Callback, typename...Args>