From 6aac9a583fed5bbd9e120c14c51ce7db9f620ae4 Mon Sep 17 00:00:00 2001 From: Brad Hubbard Date: Thu, 31 Jul 2025 09:12:23 +1000 Subject: [PATCH] mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock 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 (cherry picked from commit b4304d521f61b61515cade872824210e7d67f6db) --- src/mgr/DaemonState.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 0688db81bb1..7fc630fbf7f 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -260,9 +260,12 @@ public: template auto with_daemons_by_server(Callback&& cb, Args&&... args) const -> decltype(cb(by_server, std::forward(args)...)) { - std::shared_lock l{lock}; - - return std::forward(cb)(by_server, std::forward(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(cb)(by_server_copy, std::forward(args)...); } template -- 2.39.5