From f2c39e49988900962f2e43d663dd9a8439c82350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Wed, 28 Jun 2023 08:23:27 +0200 Subject: [PATCH] Release lock early early --- .../decomposedfs/metadata/messagepack_backend.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go index 1c9f5aae84d..bb00bf90779 100644 --- a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go +++ b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go @@ -195,9 +195,11 @@ func (b MessagePackBackend) loadAttributes(path string, source io.Reader) (map[s } metaPath := b.MetadataPath(path) + var msgBytes []byte + if source == nil { - source, err = lockedfile.Open(metaPath) // // No cached entry found. Read from storage and store in cache + source, err = lockedfile.Open(metaPath) if err != nil { if os.IsNotExist(err) { // some of the caller rely on ENOTEXISTS to be returned when the @@ -210,10 +212,11 @@ func (b MessagePackBackend) loadAttributes(path string, source io.Reader) (map[s return attribs, nil // no attributes set yet } } - defer source.(*lockedfile.File).Close() + msgBytes, err = io.ReadAll(source) + source.(*lockedfile.File).Close() + } else { + msgBytes, err = io.ReadAll(source) } - - msgBytes, err := io.ReadAll(source) if err != nil { return nil, err }