Skip to content

Commit

Permalink
fix: prevent duplicate mqtt connections (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
jburhenn authored and brocaar committed Jun 27, 2023
1 parent 6b202d1 commit a9bb4ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/chirpstack-gateway-bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/integration/mqtt/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9bb4ed

Please sign in to comment.