Skip to content

Commit

Permalink
sync2: fptree: fix race in SyncedTable (#6491)
Browse files Browse the repository at this point in the history
## Motivation

`SyncedTable` has a tiny cache for query strings to avoid heap-intensive query formatting operations (AST->SQL string) upon each SQL query being run.
The cached query string map was not protected by a mutex.
  • Loading branch information
ivan4th committed Nov 26, 2024
1 parent 9a5259c commit b30f7c2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sync2/sqlstore/syncedtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sqlstore
import (
"errors"
"fmt"
"sync"

"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/expr"
Expand All @@ -24,10 +25,13 @@ type SyncedTable struct {
Filter expr.Expr
// The binder function for the bind parameters appearing in the filter expression.
Binder Binder
mtx sync.Mutex
queries map[string]string
}

func (st *SyncedTable) cacheQuery(name string, gen func() expr.Statement) string {
st.mtx.Lock()
defer st.mtx.Unlock()
s, ok := st.queries[name]
if ok {
return s
Expand Down

0 comments on commit b30f7c2

Please sign in to comment.