From b6b76876ec00bdeeaa36d19dbc4b3dbf92edbe82 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Sun, 9 Feb 2020 00:40:54 +0300 Subject: [PATCH 1/2] fix gomap datarace: delete is not threadsafe --- gomap/gomap.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gomap/gomap.go b/gomap/gomap.go index 65331d5..1a98323 100644 --- a/gomap/gomap.go +++ b/gomap/gomap.go @@ -65,6 +65,8 @@ func (s Store) Delete(k string) error { return err } + s.lock.Lock() + defer s.lock.Unlock() delete(s.m, k) return nil } From 4e79f385e106b4a68b0f5648fe47feb79d386611 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Sun, 9 Feb 2020 00:50:11 +0300 Subject: [PATCH 2/2] add regression test --- test/test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test.go b/test/test.go index f97b8cb..3d4f03d 100644 --- a/test/test.go +++ b/test/test.go @@ -353,4 +353,14 @@ func InteractWithStore(store gokv.Store, key string, t *testing.T, waitGroup *sy if err != nil { t.Error(err) } + // Delete + err = store.Delete(key) + if err != nil { + t.Error(err) + } + // Read + _, err = store.Get(key, new(Foo)) + if err != nil { + t.Error(err) + } }