fix deadlock.

This commit is contained in:
Miroslav Šedivý 2021-09-18 00:56:03 +02:00
parent 6bd46b438e
commit 137614c087
3 changed files with 15 additions and 29 deletions

View File

@ -198,16 +198,13 @@ func (manager *SessionManagerCtx) ClearHost() {
// ---
func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, exclude interface{}) {
manager.sessionsMu.Lock()
defer manager.sessionsMu.Unlock()
for id, session := range manager.sessions {
for _, session := range manager.List() {
if !session.State().IsConnected {
continue
}
if exclude != nil {
if in, _ := utils.ArrayIn(id, exclude); in {
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
continue
}
}
@ -217,16 +214,13 @@ func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, e
}
func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface{}, exclude interface{}) {
manager.sessionsMu.Lock()
defer manager.sessionsMu.Unlock()
for id, session := range manager.sessions {
for _, session := range manager.List() {
if !session.State().IsConnected || !session.Profile().IsAdmin {
continue
}
if exclude != nil {
if in, _ := utils.ArrayIn(id, exclude); in {
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
continue
}
}

View File

@ -68,14 +68,9 @@ func (peer *WebRTCPeerCtx) Destroy() {
peer.mu.Lock()
defer peer.mu.Unlock()
if peer.connection == nil || peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
return
}
// TODO: Send webrtc disconnect event via websocket.
if peer.connection != nil {
err := peer.connection.Close()
peer.logger.Err(err).Msg("peer connection destroyed")
peer.connection = nil
}
}

View File

@ -67,21 +67,18 @@ func (peer *WebSocketPeerCtx) Send(event string, payload interface{}) {
}
func (peer *WebSocketPeerCtx) Destroy(reason string) {
peer.mu.Lock()
defer peer.mu.Unlock()
if peer.connection == nil {
return
}
peer.Send(
event.SYSTEM_DISCONNECT,
message.SystemDisconnect{
Message: reason,
})
peer.mu.Lock()
defer peer.mu.Unlock()
if peer.connection != nil {
err := peer.connection.Close()
peer.logger.Err(err).Msg("peer connection destroyed")
peer.connection = nil
}
}