Skip to content

Commit

Permalink
Fixes #345
Browse files Browse the repository at this point in the history
Also adds two more loggers on shutdown in case this happens again.

Helpful tool while debugging: https://github.com/sasha-s/go-deadlock
  • Loading branch information
Bios-Marcel committed Oct 20, 2024
1 parent 1534a28 commit 9420893
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/game/lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,20 @@ func (lobby *Lobby) handleToggleReadinessEvent(player *Player) {
func (lobby *Lobby) readyToStart() bool {
// Otherwise the game will start and gameover instantly. This can happen
// if a lobby is created and the owner refreshes.
if !lobby.HasConnectedPlayers() {
return false
}
var hasConnectedPlayers bool

for _, otherPlayer := range lobby.players {
if otherPlayer.Connected && otherPlayer.State != Ready {
if !otherPlayer.Connected {
continue
}

if otherPlayer.State != Ready {
return false
}
hasConnectedPlayers = true
}

return true
return hasConnectedPlayers
}

func handleMessage(message string, sender *Player, lobby *Lobby) {
Expand Down Expand Up @@ -1156,6 +1159,7 @@ func (lobby *Lobby) canDraw(player *Player) bool {
func (lobby *Lobby) Shutdown() {
lobby.mutex.Lock()
defer lobby.mutex.Unlock()
log.Println("Lobby Shutdown: Mutex aqcuired")

lobby.Broadcast(&EventTypeOnly{Type: EventTypeShutdown})
}
1 change: 1 addition & 0 deletions internal/state/lobbies.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func GetLobby(id string) *game.Lobby {
func ShutdownLobbiesGracefully() {
globalStateMutex.Lock()
defer globalStateMutex.Unlock()
log.Println("Shutdown: Mutex aqcuired")

for _, lobby := range lobbies {
// Since a reconnect requires a lookup to the state, all attempts to
Expand Down

0 comments on commit 9420893

Please sign in to comment.