ソースを参照

add checks for nil mqclient

Matthew R. Kasun 3 年 前
コミット
a6afb85633
2 ファイル変更6 行追加0 行削除
  1. 3 0
      mq/util.go
  2. 3 0
      netclient/functions/mqpublish.go

+ 3 - 0
mq/util.go

@@ -65,6 +65,9 @@ func publish(node *models.Node, dest string, msg []byte) error {
 	if encryptErr != nil {
 		return encryptErr
 	}
+	if mqclient == nil {
+		return errors.New("cannot publish mqclient not connected")
+	}
 	if token := mqclient.Publish(dest, 0, true, encrypted); !token.WaitTimeout(MQ_TIMEOUT*time.Second) || token.Error() != nil {
 		var err error
 		if token.Error() == nil {

+ 3 - 0
netclient/functions/mqpublish.go

@@ -146,6 +146,9 @@ func publish(nodeCfg *config.ClientConfig, dest string, msg []byte, qos byte) er
 	if err != nil {
 		return err
 	}
+	if mqclient == nil {
+		return errors.New("unable to publish - no mqclient")
+	}
 
 	if token := mqclient.Publish(dest, qos, false, encrypted); !token.WaitTimeout(30*time.Second) || token.Error() != nil {
 		logger.Log(0, "could not connect to broker at "+nodeCfg.Server.Server+":"+nodeCfg.Server.MQPort)