From 38d0c09d598416383843548edf55f5a20eaffcf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 4 Jul 2023 08:51:57 +0200 Subject: [PATCH] Async-cache a map copy for thread-safety reasons --- .../utils/decomposedfs/metadata/messagepack_backend.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go index 298e64fa584..d489c73b2c3 100644 --- a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go +++ b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go @@ -257,7 +257,12 @@ func (b MessagePackBackend) loadAttributes(ctx context.Context, path string, sou } } - go func() { _ = b.metaCache.PushToCache(b.cacheKey(path), attribs) }() + // Prepare a copy to push to cache. Pushing the original map isn't thread-safe + attribsCopy := map[string][]byte{} + for k, v := range attribs { + attribsCopy[k] = v + } + go func() { _ = b.metaCache.PushToCache(b.cacheKey(path), attribsCopy) }() return attribs, nil }