Skip to content

Commit 506d193

Browse files
committed
Backend: switch to sync.RWMutex for the connections struct.
1 parent 5853568 commit 506d193

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

backend/server/ws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (connection *connection) handleFrame(ctx context.Context) error {
4141

4242
type connections struct {
4343
data map[*connection]bool
44-
mutex sync.Mutex
44+
mutex sync.RWMutex
4545
}
4646

4747
func newConnections() connections {
@@ -61,8 +61,8 @@ func (connections *connections) delete(key *connection) {
6161
}
6262

6363
func (connections *connections) close() {
64-
connections.mutex.Lock()
65-
defer connections.mutex.Unlock()
64+
connections.mutex.RLock()
65+
defer connections.mutex.RUnlock()
6666

6767
for connection := range connections.data {
6868
connection.Close(websocket.StatusNormalClosure, "server shutting down")

0 commit comments

Comments
 (0)