mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
fixed deadlock in Websocket write
* properly unlock mutex to avoid deadlock see #572
This commit is contained in:
@@ -475,14 +475,15 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
|
||||
|
||||
if response.Account == number {
|
||||
a.wsMutex.Lock()
|
||||
defer a.wsMutex.Unlock()
|
||||
err = ws.WriteMessage(websocket.TextMessage, []byte(data))
|
||||
if err != nil {
|
||||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
|
||||
log.Error("Couldn't write message: " + err.Error())
|
||||
}
|
||||
a.wsMutex.Unlock()
|
||||
return
|
||||
}
|
||||
a.wsMutex.Unlock()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -493,12 +494,13 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
|
||||
return
|
||||
}
|
||||
a.wsMutex.Lock()
|
||||
defer a.wsMutex.Unlock()
|
||||
err = ws.WriteMessage(websocket.TextMessage, errorMsgBytes)
|
||||
if err != nil {
|
||||
log.Error("Couldn't write message: " + err.Error())
|
||||
a.wsMutex.Unlock()
|
||||
return
|
||||
}
|
||||
a.wsMutex.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user