From d93bd76b45bac1d51285022548ab1878f1353366 Mon Sep 17 00:00:00 2001 From: Ragot Geoffrey Date: Thu, 23 Feb 2023 16:13:44 +0100 Subject: [PATCH] fix: concurrent map read/writes (#90) --- pkg/storage/sqlstorage/driver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/storage/sqlstorage/driver.go b/pkg/storage/sqlstorage/driver.go index b1da57e50..6369157a9 100644 --- a/pkg/storage/sqlstorage/driver.go +++ b/pkg/storage/sqlstorage/driver.go @@ -5,6 +5,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "sync" "github.com/formancehq/stack/libs/go-libs/logging" "github.com/huandu/go-sqlbuilder" @@ -102,6 +103,7 @@ type Driver struct { db DB systemSchema Schema registeredLedgers map[string]struct{} + lock sync.Mutex } func (d *Driver) GetSystemStore() storage.SystemStore { @@ -114,6 +116,8 @@ func (d *Driver) GetLedgerStore(ctx context.Context, name string, create bool) ( if name == SystemSchema { return nil, false, errors.New("reserved name") } + d.lock.Lock() + defer d.lock.Unlock() ctx, span := opentelemetry.Start(ctx, "Load store") defer span.End()