mirror of
https://github.com/kerberos-io/agent.git
synced 2026-09-08 17:48:35 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b058c1e742 | ||
|
|
7671b1c2c3 |
@@ -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
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user