summaryrefslogtreecommitdiff
path: root/internal/flamegraph/livetrie.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-27 08:08:37 +0300
committerPaul Buetow <paul@buetow.org>2026-05-27 08:08:37 +0300
commit9b6be4cf0fcaf6426886c2a0ecf55f06965f1a3f (patch)
tree8cd7ca946e928fe2fe649e8cfda1b2f295f7bd8e /internal/flamegraph/livetrie.go
parent60e9a8fc836dc60ca5038890f3a0fa646ee2450b (diff)
flamegraph: guard SnapshotJSON cache writes (5p)
Diffstat (limited to 'internal/flamegraph/livetrie.go')
-rw-r--r--internal/flamegraph/livetrie.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/flamegraph/livetrie.go b/internal/flamegraph/livetrie.go
index 47299e6..4554780 100644
--- a/internal/flamegraph/livetrie.go
+++ b/internal/flamegraph/livetrie.go
@@ -234,8 +234,11 @@ func (lt *LiveTrie) SnapshotJSON() ([]byte, uint64) {
}
lt.cacheMu.Lock()
- lt.cacheVersion = version
- lt.cacheJSON = slices.Clone(payload)
+ // Only commit if no concurrent caller stored a newer version.
+ if version >= lt.cacheVersion {
+ lt.cacheVersion = version
+ lt.cacheJSON = slices.Clone(payload)
+ }
lt.cacheMu.Unlock()
return payload, version