Skip to content

Commit

Permalink
Optimize locking
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed May 11, 2024
1 parent bce29e3 commit 907d844
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (b *WSBackend) getConnection(conn wasabi.Connection) (*websocket.Conn, erro

b.lock.Lock()
b.connections[conn.ID()] = c
b.lock.Unlock()

go b.responseHandler(c, conn)
b.lock.Unlock()

return c, nil
}
Expand All @@ -68,9 +68,10 @@ func (b *WSBackend) responseHandler(server *websocket.Conn, client wasabi.Connec
defer func() {
b.lock.Lock()
delete(b.connections, client.ID())
b.lock.Unlock()

server.Close(websocket.StatusNormalClosure, "")
client.Close(websocket.StatusNormalClosure, "")
b.lock.Unlock()
}()

buffer := bytes.NewBuffer(make([]byte, 0))
Expand Down

0 comments on commit 907d844

Please sign in to comment.