From f3289395ae503ec6c236219a10e8d96a4eecce0d Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Wed, 7 Aug 2024 17:07:12 +0200 Subject: [PATCH] fixed deadlock in Websocket write * properly unlock mutex to avoid deadlock see #572 --- src/api/api.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index fb1a5f6..06443a1 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -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() } } }