From 1bf2a994c22acd4311c79fa203f4cb4945cd5dd3 Mon Sep 17 00:00:00 2001 From: Mikhail Rakhmanov Date: Wed, 4 Jun 2025 15:38:51 +0200 Subject: [PATCH] Remove nested locks in treestats collector --- commonspace/object/tree/synctree/treestats.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commonspace/object/tree/synctree/treestats.go b/commonspace/object/tree/synctree/treestats.go index 7effb3d2..9655f13b 100644 --- a/commonspace/object/tree/synctree/treestats.go +++ b/commonspace/object/tree/synctree/treestats.go @@ -25,9 +25,13 @@ func (t *TreeStatsCollector) Register(tree *syncTree) { func (t *TreeStatsCollector) Collect() []TreeStats { t.mutex.Lock() - defer t.mutex.Unlock() - stats := make([]TreeStats, 0, len(t.trees)) + trees := make([]*syncTree, 0, len(t.trees)) for _, tree := range t.trees { + trees = append(trees, tree) + } + t.mutex.Unlock() + stats := make([]TreeStats, 0, len(t.trees)) + for _, tree := range trees { tree.Lock() stats = append(stats, TreeStats{ TreeLen: tree.Len(),