fix(backend): fix crash when trying to update player data concurrently

This commit is contained in:
2025-03-11 12:32:36 +01:00
parent d4f194b146
commit a4a26f04d4
4 changed files with 31 additions and 0 deletions

View File

@ -35,6 +35,7 @@ type Player struct {
Cards []Card `json:"-"`
Connection WebsocketConnection `bson:"-" json:"-"`
InactivityTimeout int `bson:"-" json:"-"`
Mutex *sync.Mutex
}
func (player *Player) ResetInactivity() {
@ -93,6 +94,9 @@ func (room *Room) AppendPlayer(player *Player) {
func (room *Room) RemovePlayer(target Player) bool {
room.PlayersMutex.Lock()
defer room.PlayersMutex.Unlock()
target.Mutex.Lock()
defer target.Mutex.Unlock()
return room.RemovePlayerUnsafe(target)
}