From: Brad Hubbard Date: Wed, 30 Jul 2025 23:12:23 +0000 (+1000) Subject: mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b4304d521f61b61515cade872824210e7d67f6db;p=ceph.git 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 --- 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