Skip to content

Commit 28be1fb

Browse files
committed
add some error checking
1 parent bbd73f8 commit 28be1fb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/lobbyServer/lobby.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"runtime/debug"
1414
"strconv"
1515
"strings"
16+
"sync"
1617
"time"
1718

1819
"github.com/go-logr/logr"
@@ -72,6 +73,7 @@ type LobbyServer struct {
7273
CloseOnFinish bool
7374
quitChannel chan bool
7475
Timeout int
76+
SendMutex sync.Mutex
7577
}
7678

7779
type RoomData struct {
@@ -104,7 +106,9 @@ const NetplayAPIVersion = 17
104106

105107
func (s *LobbyServer) sendData(ws *websocket.Conn, message SocketMessage) error {
106108
// s.Logger.Info("sending message", "message", message, "address", ws.Request().RemoteAddr)
109+
s.SendMutex.Lock()
107110
err := ws.WriteJSON(message)
111+
s.SendMutex.Unlock()
108112
if err != nil {
109113
return fmt.Errorf("error sending data: %s", err.Error())
110114
}

0 commit comments

Comments
 (0)