QR2: Fix mutex deadlocks

Yay the detection helped a lot
This commit is contained in:
mkwcat
2023-12-30 14:26:49 -05:00
parent fe34c0d021
commit 2ee1a1de9d
3 changed files with 5 additions and 11 deletions

View File

@@ -61,7 +61,9 @@ func heartbeat(moduleName string, conn net.PacketConn, addr net.Addr, buffer []b
if statechanged == "2" {
logging.Notice(moduleName, "Client session shutdown")
mutex.Lock()
removeSession(lookupAddr)
mutex.Unlock()
return
}
}

View File

@@ -15,6 +15,7 @@ var logins = map[uint32]*LoginInfo{}
func Login(profileID uint32, gameCode string, inGameName string, consoleFriendCode uint64, publicIP string, needsExploit bool, deviceAuthenticated bool) {
mutex.Lock()
defer mutex.Unlock()
logins[profileID] = &LoginInfo{
ProfileID: profileID,
@@ -26,12 +27,11 @@ func Login(profileID uint32, gameCode string, inGameName string, consoleFriendCo
DeviceAuthenticated: deviceAuthenticated,
Session: nil,
}
mutex.Unlock()
}
func SetDeviceAuthenticated(profileID uint32) {
mutex.Lock()
defer mutex.Unlock()
if login, exists := logins[profileID]; exists {
login.DeviceAuthenticated = true
@@ -39,23 +39,18 @@ func SetDeviceAuthenticated(profileID uint32) {
login.Session.Data["+deviceauth"] = "1"
}
}
mutex.Unlock()
}
func Logout(profileID uint32) {
mutex.Lock()
defer mutex.Unlock()
// Delete login's session
if login, exists := logins[profileID]; exists {
if login.Session != nil {
mutex.Unlock()
removeSession(makeLookupAddr(login.Session.Addr.String()))
mutex.Lock()
}
}
delete(logins, profileID)
mutex.Unlock()
}

View File

@@ -43,9 +43,6 @@ var (
// Remove a session.
func removeSession(addr uint64) {
mutex.Lock()
defer mutex.Unlock()
session := sessions[addr]
if session == nil {
return