Skip to content

Commit

Permalink
Add mutex lock to tracingContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Jul 25, 2022
1 parent 50d1c11 commit 42c660a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cachemulti
import (
"fmt"
"io"
"sync"

dbm "github.com/tendermint/tm-db"

Expand All @@ -23,8 +24,9 @@ type Store struct {
stores map[types.StoreKey]types.CacheWrap
keys map[string]types.StoreKey

traceWriter io.Writer
traceContext types.TraceContext
traceWriter io.Writer
traceContext types.TraceContext
traceContextMutex sync.RWMutex

listeners map[types.StoreKey][]types.WriteListener
}
Expand Down Expand Up @@ -96,6 +98,8 @@ func (cms Store) SetTracer(w io.Writer) types.MultiStore {
// be overwritten. It is implied that the caller should update the context when
// necessary between tracing operations. It returns a modified MultiStore.
func (cms Store) SetTracingContext(tc types.TraceContext) types.MultiStore {
cms.traceContextMutex.Lock()
defer cms.traceContextMutex.Unlock()
if cms.traceContext != nil {
for k, v := range tc {
cms.traceContext[k] = v
Expand Down
2 changes: 2 additions & 0 deletions store/v2alpha1/multi/cache_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (cs *cacheStore) GetKVStore(skey types.StoreKey) types.KVStore {

// Write implements CacheMultiStore.
func (cs *cacheStore) Write() {
cs.traceListenMixin.traceContextMutex.Lock()
defer cs.traceListenMixin.traceContextMutex.Unlock()
for _, sub := range cs.substores {
sub.Write()
}
Expand Down

0 comments on commit 42c660a

Please sign in to comment.