Skip to content

Commit

Permalink
fix: concurrent map read/writes (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Feb 23, 2023
1 parent 4466ec6 commit d93bd76
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/storage/sqlstorage/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -102,6 +103,7 @@ type Driver struct {
db DB
systemSchema Schema
registeredLedgers map[string]struct{}
lock sync.Mutex
}

func (d *Driver) GetSystemStore() storage.SystemStore {
Expand All @@ -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()
Expand Down

0 comments on commit d93bd76

Please sign in to comment.