From 376a6e2d997bef5cfec0648fdac4d9dfb6a044eb Mon Sep 17 00:00:00 2001 From: Thomas Quandalle Date: Wed, 22 Jun 2022 21:01:30 +0200 Subject: [PATCH] BUG: introduced a deadlock --- machinery/src/cloud/Cloud.go | 5 +++-- machinery/src/routers/mqtt/main.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/machinery/src/cloud/Cloud.go b/machinery/src/cloud/Cloud.go index 0ba530c..5d0c4ae 100644 --- a/machinery/src/cloud/Cloud.go +++ b/machinery/src/cloud/Cloud.go @@ -278,15 +278,16 @@ func HandleLiveStreamHD(livestreamCursor *pubsub.QueueCursor, configuration *mod } else { log.Log.Info("HandleLiveStreamHD: Waiting for peer connections.") for handshake := range communication.HandleLiveHDHandshake { - webrtc.CandidatesMutex.Lock() log.Log.Info("HandleLiveStreamHD: setting up a peer connection.") key := config.Key + "/" + handshake.Cuuid + webrtc.CandidatesMutex.Lock() _, ok := webrtc.CandidateArrays[key] if !ok { webrtc.CandidateArrays[key] = make(chan string, 30) } - webrtc.InitializeWebRTCConnection(configuration, communication, mqttClient, track, handshake, webrtc.CandidateArrays[key]) webrtc.CandidatesMutex.Unlock() + webrtc.InitializeWebRTCConnection(configuration, communication, mqttClient, track, handshake, webrtc.CandidateArrays[key]) + } } } diff --git a/machinery/src/routers/mqtt/main.go b/machinery/src/routers/mqtt/main.go index 5db34ae..323156c 100644 --- a/machinery/src/routers/mqtt/main.go +++ b/machinery/src/routers/mqtt/main.go @@ -159,16 +159,16 @@ func MQTTListenerHandleLiveHDCandidates(mqttClient mqtt.Client, hubKey string, c var candidate models.Candidate json.Unmarshal(msg.Payload(), &candidate) if candidate.CloudKey == config.Key { - webrtc.CandidatesMutex.Lock() key := candidate.CloudKey + "/" + candidate.Cuuid candidatesExists := false var channel chan string for !candidatesExists { + webrtc.CandidatesMutex.Lock() channel, candidatesExists = webrtc.CandidateArrays[key] + webrtc.CandidatesMutex.Unlock() } log.Log.Info("MQTTListenerHandleLiveHDCandidates: " + string(msg.Payload())) channel <- string(msg.Payload()) - webrtc.CandidatesMutex.Unlock() } }) }