From 7c0e25e551196e1bf0c6dc08475123ef5ecde8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Fri, 12 Jul 2024 10:32:27 +0200 Subject: [PATCH] fix: kvsmock race condition --- pkg/accesscontrol/kvs/mock/kvs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/accesscontrol/kvs/mock/kvs.go b/pkg/accesscontrol/kvs/mock/kvs.go index 0d5b1eb8569..a3d2ec3f56c 100644 --- a/pkg/accesscontrol/kvs/mock/kvs.go +++ b/pkg/accesscontrol/kvs/mock/kvs.go @@ -15,6 +15,7 @@ import ( ) var lock = &sync.Mutex{} +var lockGetPut = &sync.Mutex{} type single struct { memoryMock map[string]map[string][]byte @@ -51,12 +52,16 @@ type mockKeyValueStore struct { var _ kvs.KeyValueStore = (*mockKeyValueStore)(nil) func (m *mockKeyValueStore) Get(_ context.Context, key []byte) ([]byte, error) { + lockGetPut.Lock() + defer lockGetPut.Unlock() mem := getMemory() val := mem[m.address.String()][hex.EncodeToString(key)] return val, nil } func (m *mockKeyValueStore) Put(_ context.Context, key []byte, value []byte) error { + lockGetPut.Lock() + defer lockGetPut.Unlock() mem := getMemory() if _, ok := mem[m.address.String()]; !ok { mem[m.address.String()] = make(map[string][]byte)