From a9bb4ed7f315aacb597a218fb8aa4055287e8ec4 Mon Sep 17 00:00:00 2001 From: Jake Burhenn Date: Tue, 27 Jun 2023 02:23:46 -0600 Subject: [PATCH] fix: prevent duplicate mqtt connections (#229) --- cmd/chirpstack-gateway-bridge/cmd/root.go | 2 +- internal/integration/mqtt/backend.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/chirpstack-gateway-bridge/cmd/root.go b/cmd/chirpstack-gateway-bridge/cmd/root.go index e9159a86..5ad16bde 100644 --- a/cmd/chirpstack-gateway-bridge/cmd/root.go +++ b/cmd/chirpstack-gateway-bridge/cmd/root.go @@ -62,7 +62,7 @@ func init() { viper.SetDefault("integration.mqtt.state_retained", true) viper.SetDefault("integration.mqtt.keep_alive", 30*time.Second) viper.SetDefault("integration.mqtt.max_reconnect_interval", time.Minute) - viper.SetDefault("integration.mqtt.max_token_wait", 5*time.Second) + viper.SetDefault("integration.mqtt.max_token_wait", time.Minute) viper.SetDefault("integration.mqtt.auth.generic.servers", []string{"tcp://127.0.0.1:1883"}) viper.SetDefault("integration.mqtt.auth.generic.clean_session", true) diff --git a/internal/integration/mqtt/backend.go b/internal/integration/mqtt/backend.go index d433f006..2e5d511a 100644 --- a/internal/integration/mqtt/backend.go +++ b/internal/integration/mqtt/backend.go @@ -379,6 +379,9 @@ func (b *Backend) connect() error { return errors.Wrap(err, "integration/mqtt: update authentication error") } + if b.conn != nil { + b.conn.Disconnect(250) + } b.conn = paho.NewClient(b.clientOpts) if err := tokenWrapper(b.conn.Connect(), b.maxTokenWait); err != nil { return err