From 59a0774aef04bdd91e17ff23ed2675de59c1de48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CWind=E2=80=9D?= <573966@qq.com> Date: Tue, 12 Sep 2023 10:48:43 +0800 Subject: [PATCH] fixed nil pointer dereference #72 --- cmd/config/single.yml | 4 ++-- plugin/bridge/kafka/kafka.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/config/single.yml b/cmd/config/single.yml index b11a886..e1a6e7a 100644 --- a/cmd/config/single.yml +++ b/cmd/config/single.yml @@ -5,9 +5,9 @@ bridge-path: ./cmd/config/bridge-kafka.yml #The bridge config file path pprof-enable: false #Whether to enable the performance analysis tool http://ip:6060 auth: - way: 1 #Authentication way: 0 anonymous, 1 username and password, 2 clientid + way: 0 #Authentication way: 0 anonymous, 1 username and password, 2 clientid datasource: 1 #Optional items:0 free、1 redis、2 mysql、3 postgresql、4 http ... - conf-path: ./config/auth-redis.yml #The config file path should correspond to the auth-datasource + conf-path: ./cmd/config/auth-redis.yml #The config file path should correspond to the auth-datasource mqtt: tcp: :1883 diff --git a/plugin/bridge/kafka/kafka.go b/plugin/bridge/kafka/kafka.go index cccc97b..ec4f873 100644 --- a/plugin/bridge/kafka/kafka.go +++ b/plugin/bridge/kafka/kafka.go @@ -276,7 +276,10 @@ func (b *Bridge) OnDisconnect(cl *mqtt.Client, err error, expire bool) { ClientID: cl.ID, Username: string(cl.Properties.Username), Timestamp: timestamp, - Payload: []byte(err.Error()), + } + + if err != nil { + msg.Payload = []byte(err.Error()) } data, err := msg.MarshalBinary()