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:
@ -58,7 +58,7 @@ func (s *smtpSession) AuthPlain(username, password string) error {
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid username or password")
|
||||
}, &s.usersLock)
|
||||
}, s.usersLock)
|
||||
}
|
||||
|
||||
func (s *smtpSession) Reset() {
|
||||
@ -92,5 +92,5 @@ func (s *smtpSession) Data(r io.Reader) error {
|
||||
}
|
||||
|
||||
return user.SendMail(s.authID, s.from, s.to, r)
|
||||
}, &s.usersLock)
|
||||
}, s.usersLock)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user