Skip to content

Commit 73196fd

Browse files
committed
fix jsondb lock
1 parent 33e921b commit 73196fd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/settings/jsondb.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type JsonDB struct {
2222
}
2323

2424
var jsonDbLocks = make(map[string]*sync.Mutex)
25+
var jsonDbLocksMutex sync.Mutex
2526

2627
func NewJsonDB() TorrServerDB {
2728
settingsDB := &JsonDB{
@@ -109,18 +110,22 @@ func (v *JsonDB) Rem(xPath, name string) {
109110
}
110111

111112
func (v *JsonDB) lock(filename string) {
112-
var mtx sync.Mutex
113-
if mtx, ok := jsonDbLocks[filename]; !ok {
114-
mtx = new(sync.Mutex)
115-
jsonDbLocks[v.Path] = mtx
113+
jsonDbLocksMutex.Lock()
114+
mtx, ok := jsonDbLocks[filename]
115+
if !ok {
116+
mtx = &sync.Mutex{}
117+
jsonDbLocks[filename] = mtx
116118
}
119+
jsonDbLocksMutex.Unlock()
117120
mtx.Lock()
118121
}
119122

120123
func (v *JsonDB) unlock(filename string) {
124+
jsonDbLocksMutex.Lock()
121125
if mtx, ok := jsonDbLocks[filename]; ok {
122126
mtx.Unlock()
123127
}
128+
jsonDbLocksMutex.Unlock()
124129
}
125130

126131
func (v *JsonDB) xPathToFilename(xPath string) (string, error) {

0 commit comments

Comments
 (0)