From b4304d521f61b61515cade872824210e7d67f6db 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 --- 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 d78e819405b..960cbcbd302 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -261,9 +261,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.47.3