fixed deadlock in json-rpc mode

* properly unlock mutex to avoid deadlock

see #572
This commit is contained in:
Bernhard B
2024-08-09 23:02:40 +02:00
parent f3289395ae
commit e6ff51e3d8
2 changed files with 4 additions and 3 deletions

View File

@@ -531,10 +531,11 @@ func (a *Api) wsPing(ws *websocket.Conn, stop chan struct{}) {
return return
case <-pingTicker.C: case <-pingTicker.C:
a.wsMutex.Lock() a.wsMutex.Lock()
defer a.wsMutex.Unlock()
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil { if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
a.wsMutex.Unlock()
return return
} }
a.wsMutex.Unlock()
} }
} }
} }

View File

@@ -229,14 +229,14 @@ func (r *JsonRpc2Client) GetReceiveChannel() (chan JsonRpc2ReceivedMessage, stri
} }
r.receivedMessagesMutex.Lock() r.receivedMessagesMutex.Lock()
defer r.receivedMessagesMutex.Unlock()
r.receivedMessagesChannels[channelUuid.String()] = c r.receivedMessagesChannels[channelUuid.String()] = c
r.receivedMessagesMutex.Unlock()
return c, channelUuid.String(), nil return c, channelUuid.String(), nil
} }
func (r *JsonRpc2Client) RemoveReceiveChannel(channelUuid string) { func (r *JsonRpc2Client) RemoveReceiveChannel(channelUuid string) {
r.receivedMessagesMutex.Lock() r.receivedMessagesMutex.Lock()
defer r.receivedMessagesMutex.Unlock()
delete(r.receivedMessagesChannels, channelUuid) delete(r.receivedMessagesChannels, channelUuid)
r.receivedMessagesMutex.Unlock()
} }