fix racism condition / deadlock

This commit is contained in:
2025-01-19 00:51:49 +01:00
parent c40e4ae7ac
commit 509bc8b20b
2 changed files with 20 additions and 11 deletions

View File

@ -111,9 +111,18 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
for {
select {
case <-quitChan:
<-done // Wait for action goroutine to finish
close(done)
time.Sleep(100 * time.Millisecond) // Give time for disconnect message to be sent
done := make(chan struct{})
go func() {
<-done
close(player.QuitDone)
}()
select {
case <-done:
time.Sleep(100 * time.Millisecond)
case <-time.After(1 * time.Second):
log.Println("Shutdown timed out")
}
return
default:
// Read message length (4 bytes)