Compare commits

...

2 Commits

Author SHA1 Message Date
Cedric Verstraeten
b058c1e742 set pointers to nil 2023-02-18 22:14:33 +01:00
Cedric Verstraeten
7671b1c2c3 unsubscribe from mqtt subscriptions 2023-02-18 22:12:44 +01:00
3 changed files with 22 additions and 2 deletions

View File

@@ -56,6 +56,9 @@ func GetSnapshot() string {
content, _ := ioutil.ReadAll(reader)
// Encode as base64.
snapshot = base64.StdEncoding.EncodeToString(content)
// Close reader
reader = nil
}
return snapshot
}
@@ -146,6 +149,9 @@ func OpenConfig(configuration *models.Configuration) {
conjungo.Merge(&s3, configuration.CustomConfig.S3, opts)
configuration.Config.S3 = &s3
// Cleanup
opts = nil
} else if os.Getenv("DEPLOYMENT") == "" || os.Getenv("DEPLOYMENT") == "agent" {
// Local deployment means we do a stand-alone installation

View File

@@ -214,21 +214,27 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
time.Sleep(time.Second * 1)
infile.Close()
infile = nil
queue.Close()
queue = nil
if subStreamEnabled {
subInfile.Close()
subInfile = nil
subQueue.Close()
subQueue = nil
}
close(communication.HandleONVIF)
close(communication.HandleLiveHDHandshake)
close(communication.HandleMotion)
routers.DisconnectMQTT(mqttClient)
routers.DisconnectMQTT(mqttClient, &configuration.Config)
// Wait a few seconds to stop the decoder.
time.Sleep(time.Second * 3)
decoder.Close()
decoder = nil
if subStreamEnabled {
subDecoder.Close()
subDecoder = nil
}
// Waiting for some seconds to make sure everything is properly closed.
log.Log.Info("RunAgent: waiting 3 seconds to make sure everything is properly closed.")

View File

@@ -193,8 +193,16 @@ func MQTTListenerHandleONVIF(mqttClient mqtt.Client, hubKey string, configuratio
})
}
func DisconnectMQTT(mqttClient mqtt.Client) {
func DisconnectMQTT(mqttClient mqtt.Client, config *models.Config) {
if mqttClient != nil {
// Cleanup all subscriptions.
mqttClient.Unsubscribe("kerberos/" + config.HubKey + "/device/" + config.Key + "/request-live")
mqttClient.Unsubscribe(config.Key + "/register")
mqttClient.Unsubscribe("kerberos/webrtc/keepalivehub/" + config.Key)
mqttClient.Unsubscribe("kerberos/webrtc/peers/" + config.Key)
mqttClient.Unsubscribe("candidate/cloud")
mqttClient.Unsubscribe("kerberos/onvif/" + config.Key)
mqttClient.Disconnect(1000)
mqttClient = nil
}
}