Skip to content

Commit

Permalink
fixed deadlock in Websocket write
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 7, 2024
1 parent a6624c5 commit f328939
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
}
Expand Down

0 comments on commit f328939

Please sign in to comment.