mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-07-28 01:27:58 +00:00
fix(evolution): add ok check for LoadOrStore type assertion in lockStoreFile
This commit is contained in:
+10
-1
@@ -555,7 +555,16 @@ func isInvalidJSON(err error) bool {
|
||||
|
||||
func lockStoreFile(path string) func() {
|
||||
actual, _ := storeFileLocks.LoadOrStore(path, &sync.Mutex{})
|
||||
mu := actual.(*sync.Mutex)
|
||||
mu, ok := actual.(*sync.Mutex)
|
||||
if !ok {
|
||||
// Delete the corrupted entry so that the next LoadOrStore
|
||||
// atomically creates a fresh mutex. Multiple goroutines may
|
||||
// race to Delete, but LoadOrStore ensures they all converge
|
||||
// on the same mutex before entering the critical section.
|
||||
storeFileLocks.Delete(path)
|
||||
actual, _ = storeFileLocks.LoadOrStore(path, &sync.Mutex{})
|
||||
mu = actual.(*sync.Mutex)
|
||||
}
|
||||
mu.Lock()
|
||||
return mu.Unlock
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user