Skip to content

Commit e6ff51e

Browse files
committed
fixed deadlock in json-rpc mode
* properly unlock mutex to avoid deadlock see #572
1 parent f328939 commit e6ff51e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/api/api.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,11 @@ func (a *Api) wsPing(ws *websocket.Conn, stop chan struct{}) {
531531
return
532532
case <-pingTicker.C:
533533
a.wsMutex.Lock()
534-
defer a.wsMutex.Unlock()
535534
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
535+
a.wsMutex.Unlock()
536536
return
537537
}
538+
a.wsMutex.Unlock()
538539
}
539540
}
540541
}

src/client/jsonrpc2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ func (r *JsonRpc2Client) GetReceiveChannel() (chan JsonRpc2ReceivedMessage, stri
229229
}
230230

231231
r.receivedMessagesMutex.Lock()
232-
defer r.receivedMessagesMutex.Unlock()
233232
r.receivedMessagesChannels[channelUuid.String()] = c
233+
r.receivedMessagesMutex.Unlock()
234234

235235
return c, channelUuid.String(), nil
236236
}
237237

238238
func (r *JsonRpc2Client) RemoveReceiveChannel(channelUuid string) {
239239
r.receivedMessagesMutex.Lock()
240-
defer r.receivedMessagesMutex.Unlock()
241240
delete(r.receivedMessagesChannels, channelUuid)
241+
r.receivedMessagesMutex.Unlock()
242242
}

0 commit comments

Comments
 (0)