Skip to content

Commit

Permalink
fixed deadlock in json-rpc mode
Browse files Browse the repository at this point in the history
* properly unlock mutex to avoid deadlock

see #572
  • Loading branch information
bbernhard committed Aug 9, 2024
1 parent f328939 commit e6ff51e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,11 @@ func (a *Api) wsPing(ws *websocket.Conn, stop chan struct{}) {
return
case <-pingTicker.C:
a.wsMutex.Lock()
defer a.wsMutex.Unlock()
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
a.wsMutex.Unlock()
return
}
a.wsMutex.Unlock()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ func (r *JsonRpc2Client) GetReceiveChannel() (chan JsonRpc2ReceivedMessage, stri
}

r.receivedMessagesMutex.Lock()
defer r.receivedMessagesMutex.Unlock()
r.receivedMessagesChannels[channelUuid.String()] = c
r.receivedMessagesMutex.Unlock()

return c, channelUuid.String(), nil
}

func (r *JsonRpc2Client) RemoveReceiveChannel(channelUuid string) {
r.receivedMessagesMutex.Lock()
defer r.receivedMessagesMutex.Unlock()
delete(r.receivedMessagesChannels, channelUuid)
r.receivedMessagesMutex.Unlock()
}

0 comments on commit e6ff51e

Please sign in to comment.