Skip to content

Commit

Permalink
sqlx.mpr race condition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Jan 19, 2017
1 parent cac998c commit a501ce9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"reflect"
"strings"
"sync"

"github.com/jmoiron/sqlx/reflectx"
)
Expand All @@ -30,8 +31,14 @@ var origMapper = reflect.ValueOf(NameMapper)
// importers have time to customize the NameMapper.
var mpr *reflectx.Mapper

// mprMu protects mpr.
var mprMu sync.Mutex

// mapper returns a valid mapper using the configured NameMapper func.
func mapper() *reflectx.Mapper {
mprMu.Lock()
defer mprMu.Unlock()

if mpr == nil {
mpr = reflectx.NewMapperFunc("db", NameMapper)
} else if origMapper != reflect.ValueOf(NameMapper) {
Expand Down

0 comments on commit a501ce9

Please sign in to comment.