Skip to content

Commit f328939

Browse files
committed
fixed deadlock in Websocket write
* properly unlock mutex to avoid deadlock see #572
1 parent a6624c5 commit f328939

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/api/api.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,15 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
475475

476476
if response.Account == number {
477477
a.wsMutex.Lock()
478-
defer a.wsMutex.Unlock()
479478
err = ws.WriteMessage(websocket.TextMessage, []byte(data))
480479
if err != nil {
481480
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
482481
log.Error("Couldn't write message: " + err.Error())
483482
}
483+
a.wsMutex.Unlock()
484484
return
485485
}
486+
a.wsMutex.Unlock()
486487
}
487488
}
488489
} else {
@@ -493,12 +494,13 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
493494
return
494495
}
495496
a.wsMutex.Lock()
496-
defer a.wsMutex.Unlock()
497497
err = ws.WriteMessage(websocket.TextMessage, errorMsgBytes)
498498
if err != nil {
499499
log.Error("Couldn't write message: " + err.Error())
500+
a.wsMutex.Unlock()
500501
return
501502
}
503+
a.wsMutex.Unlock()
502504
}
503505
}
504506
}

0 commit comments

Comments
 (0)