fixed bug in golang channel handling (json-rpc mode)

* golang channels are meant to be 1:1 channels, so if multiple
  goroutines listen on the same channel for messages, only one will
  receive the message and the others are not, which lead to lost
  messages.

  In order to fix that, we create a dedicated golang channel for every
  websocket connection.

see #451
This commit is contained in:
Bernhard B
2023-12-11 22:18:23 +01:00
parent 844f1d7b91
commit 3d7b73560a
3 changed files with 38 additions and 15 deletions

View File

@@ -390,7 +390,7 @@ func (a *Api) SendV2(c *gin.Context) {
}
func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan struct{}) {
receiveChannel, err := a.signalClient.GetReceiveChannel()
receiveChannel, channelUuid, err := a.signalClient.GetReceiveChannel()
if err != nil {
log.Error("Couldn't get receive channel: ", err.Error())
return
@@ -399,6 +399,7 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
for {
select {
case <-stop:
a.signalClient.RemoveReceiveChannel(channelUuid)
ws.Close()
return
case msg := <-receiveChannel: