forked from Silverfish/proton-bridge
Other(refactor): Sort safe.Mutex types before locking to prevent deadlocks
This change implements safe.Mutex and safe.RWMutex, which wrap the sync.Mutex and sync.RWMutex types and are assigned a globally unique integer ID. The safe.Lock and safe.RLock methods sort the mutexes by this integer ID before locking to ensure that locks for a given set of mutexes are always performed in the same order, avoiding deadlocks.
This commit is contained in:
@ -161,7 +161,7 @@ func (bridge *Bridge) SetGluonDir(ctx context.Context, newGluonDir string) error
|
||||
}
|
||||
|
||||
return nil
|
||||
}, &bridge.usersLock)
|
||||
}, bridge.usersLock)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetProxyAllowed() bool {
|
||||
@ -189,7 +189,7 @@ func (bridge *Bridge) SetShowAllMail(show bool) error {
|
||||
}
|
||||
|
||||
return bridge.vault.SetShowAllMail(show)
|
||||
}, &bridge.usersLock)
|
||||
}, bridge.usersLock)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetAutostart() bool {
|
||||
@ -288,7 +288,7 @@ func (bridge *Bridge) FactoryReset(ctx context.Context) {
|
||||
logrus.WithError(err).Error("failed to delete vault user")
|
||||
}
|
||||
}
|
||||
}, &bridge.usersLock)
|
||||
}, bridge.usersLock)
|
||||
|
||||
// Then delete all files.
|
||||
if err := bridge.locator.Clear(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user